Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
2,622 views
in Online Assessments by Expert (108,110 points) | 2,622 views

1 Answer

0 like 0 dislike
Best answer

Got 2 questions needed to solve in 2 hours:

 

  1.  

    For a number N, a goodArray is the smallest
    possible array that consists of only powers of
    two (2°, 21 .…. 2k) such that the sum of all the
    numbers in the array is equal to N.
    For each query that consists of three integers 1,
    r, and m, find out the product of elements
    goodArray/) through goodArray(r] modulo
    m when goodArray is sorted in non-decreasing
    order.
    Example
    For N= 26, querles = (I1, 2, 1009), [3, 3, 51
    goodArray when sorted is (2,8,16),
    For query l= 1, r= 2, m = 1009, ans=
    goodAray(1] * goodArray(2) = (2 * 8) modulo
    1009 = 16.
    For query | = 3, r= 3, m = 5, ans = goodAray=
    (16) modulo 5 = 1.
    The answer is (16, 1).

     

  2.  

    Given an array of words and an array of sentences, determine which words are anagrams of each other. Calculate how many sentences can be created by replacing any word with one of its anagrams, Example wordSet = ['listen' 'silent, 'it', 'is'] sentence = "listen it is silent Determine that listen is an anagram of silent. Those two words can be replaced with their anagrams. The four sentences that can be created are: • listen it is silent • listen it is listen • silent it is silent • silent it is listen

     

 

Below is the working code for both questions which passed all test cases

by Expert (108,110 points)
0 0
Where tf is the code?