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
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
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
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
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
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
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
We are given a string str[] as input. The goal is to count the number of anagram substrings present in str[]. Two strings are anagrams of each other if they contain the same number of characters and all characters occur in both. The order of characters can be different.“abc” is an anagram of “cba”, “bca” etc.Let us understand with examples.Input − str[] = “abccb”Output − Count of total anagram substrings are − 4Explanation − Anagrams are − (b, b), (c, c), (bc, cb), (bcc, ccb)Input − str = “aaa”Output − Count of total anagram substrings are − 4Explanation − Anagrams ... Read More
We are given a target array arr[] containing positive integers. The goal is to construct the target array arr[] using an initial array with all 0s. The operations that can be applied on a given empty array with all 0s will suffix increment/decrement operations.If we choose any index say i, then in case of suffix increment operation we will add 1 to all elements from index i till last index.In case of suffix decrement operation we will subtract 1 from all elements from index i till last index.Let us understand with examplesInput − arr[]= { 1, 2, 3 }Output − ... Read More
Suppose we have a list of requests where each list contains elements like [uid, time_sec] (uid is the user id and time_sec is the timestamp). This indicates the user whose id is uid has requested to a website at timestamp time_sec. We also have two values u and g where u denotes maximum number of requests that are allowed in any < 60 second frame for a given uid and g is the maximum number of requests that are allowed in any < 60 second frame globally. Now if we want to process each request one by one and rate ... Read More