Traverse Hierarchical Data in Oracle

Kiran P
Updated on 04-Dec-2020 04:16:13

854 Views

Problem Statement: You need to traverse the hierarchy data from top to bottom marking the level of each row in the hierarchy.Solution:Oracle provides CONNECT BY clause to specify a hierarchical query i.e. how to connect the parent nodes and child nodes and the PRIOR operator to define the join condition/s between the parent nodes, and the LEVEL pseudo-column to indicate how far from the root/parent row the current row is.Additionally, we can use the START WITH clause to indicate where to start the tree navigation. We must use the PRIOR operator to specify the column/s in the parent row that have ... Read More

Count of Distinct Rectangles Inscribed in an Equilateral Triangle in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:50:15

186 Views

We are an equilateral triangle with side length. The goal is to count the number of distinct rectangles that can be present inside the triangle such that horizontal sides of the rectangle are parallel to the base. Also all end points of the rectangle touch the dots as shown.Let us understand with examplesInput − sides=3Output − Count of distinct rectangles inscribed in an equilateral triangle are − 1Explanation − The figure above shows the rectangle.Input − sides=10Output − Count of distinct rectangles inscribed in an equilateral triangle are − 200Approach used in the below program is as followsAs from the ... Read More

Count of Strings Where Adjacent Characters Are of Difference One in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:42:00

976 Views

We are given a num number as input. The goal is to count the number of possible strings of length num such that all adjacent characters have difference between ascii values as 1.If num is 2 then strings will be “ab”, “ba”, “bc”, “cb”, ……..”yz”, “zy”.Let us understand with examplesInput − num=3Output − Count of strings where adjacent characters are of difference one are − 98Explanation − Some sample strings are: “abc”, “aba”, “cde” …..”xyx”, “zyz”, “xyz”.Input − num=2Output − Count of strings where adjacent characters are of difference one are − 50Explanation − Some sample strings are: “ab”, “ba”, ... Read More

Count of Pairs (i, j) Such That n[i] + n[j] is Maximized in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:40:23

147 Views

We are given a number num as input. The goal is to find the number of pairs of form (i, j) such that ((num%i)%j)%num is maximized and i and j both are in range [1, num].Let us understand with examplesInput − num=4Output − Count of pairs of (i, j) such that ((n % i) % j) % n is maximized are − 3Explanation − Pairs will be: (3, 2), (3, 3), (3, 4)Input − num=6Output − Count of pairs of (i, j) such that ((n % i) % j) % n is maximized are − 4Explanation − Pairs will be: ... Read More

Count of Occurrences of a 1-0+1 Pattern in a String in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:37:52

206 Views

We are given a string str containing 0s, 1s and other alphabets . It also contains patterns of the form “1(0+)1” where 0+ means any number (>0) of consecutive 0s. The goal is to find such patterns ( “1(0+)1” ) inside string str.Let us understand with examplesInput − str = “abb010bb10111011”Output − Count of occurrences of a “1(0+)1” pattern in a string are − 2Explanation − The patterns inside str are highlighted: “abb010bb10111011”, “abb010bb10111011”Input − str = “01001011001001100”Output − Count of occurrences of a “1(0+)1” pattern in a string are − 4Explanation − The patterns inside str are highlighted: “01001011001001100”, ... Read More

Count of Obtuse Angles in a Circle with Equidistant Points in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:33:06

183 Views

We are given a circle with K equidistant points on its circumference. Also we are given two points A and B. The goal is to count the number of triangles possible using these points such that they have an obtuse angle ACB( angle greater than 90o) inside them. The points A and B are such that A < B.Here K=8, A=2, B=5, count of points=2 (C, C’) such that angle LACB, LAC’B are obtuse.Let us understand with examplesInput − k=10, A=2, B=4Output − Count of obtuse angles in a circle with ‘k' equidistant points between 2 given points are − ... Read More

Count of Numbers with Digit Sum Difference in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:25:07

143 Views

We are given a number N and another number L. The goal is to find the numbers between 1 and N that have a difference between the number itself and the sum of its digits is not less than L.If N=23, L=10 then the count of such numbers will be 4.23-(2+3)=18, 22-(2+2)=18, 21-(2+1)=18, 20-(2+0)=18.All above numbers meet the conditionBut 19-(1+9)=9 which is less than L, similarly 18, 17….1.Let us understand with examplesInput − N=30 L=19Output − Count of Numbers such that difference between the number and sum of its digits not less than L are − 1Explanation − Only 30 ... Read More

Count of Words Present in All Given Sentences in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:23:07

259 Views

We are given multiple sentences in the form of strings. The goal is to count the number of words that exist in all of the sentences.Note − words containing all lowercase letters will be considered onlyIf sentences are −“ I am learning C language ”“ learning new things is easy ““ Kids are learning healthy habits “Only “learning” exists in all three. So count is 1.Let us understand with examplesInput − “The clothes were dry”, “All the kids were playing”, “Those were the best days”Output − Count of words that are present in all the given sentences are − 2Explanation ... Read More

Count Pairs Formed by Distinct Element Sub-Arrays in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:19:25

163 Views

We are given an array arr[] containing integer elements. The goal is to find the count of pairs that can be formed by elements of sub-arrays of arr[] such that each subarray has only distinct elements. If the array is [ 1, 2, 2, 3, 3 ] then subarrays with distinct elements only will be [ 1, 2 ] and [ 2, 3 ]. And pairs will be (1, 2) and (2, 3) hence count of pairs is 2.Let us understand with examplesInput − arr[] = {1, 2, 5, 3 }Output − Count of pairs formed by distinct element sub-arrays ... Read More

Count of Triangles with Total N Points and M Collinear in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:17:44

213 Views

We are given two variables n and m representing the number of points on a 2D plane. Out of n points, m points are collinear. The goal is to find the number of triangles that can be formed using these n points.Collinear points − The points that lie on the same line are called collinear. Points A and B are collinear.Given n=4 (A, B, C, D ) , m=2 (A, B)Number of triangles −Choosing any three points out of 4 = 4C3But collinear points cannot form triangle so remove possible triangles that will be counted above = 2C3Total triangles= 4C3 ... Read More

Advertisements