Hackerrank Problem Solving Intermediate Certification
Anonymous User
9166

These're the problems that've been asked in Hackerrank Problem Solving Intermediate Certification:

image
image
image

For the above Problem named Sorted Sums:

I've basically done brute force and out of 15 test cases, 11 were passed and 4 were TLE.
Approach is nothing but sorting (basically merging (done it linearly, didn't use Binary Search to insert)) the next element with previous sorted array. i.e.. for a = [9,5,8],
I've 1st merged [] and 9 (becomes [9]) and calculated sum for it based on the equation, and then merged 5 with [9] which became [5,9] and then calculated sum for it and so on.

Is there any better way to do this ?? ( I couldn't find any overlapping sub-problems (may be I couldn't think properly or something) for DP) ?

For the second Problem: Find all the pairs whose bit wise AND is a power of 2
image
image
image

I've basically looped for all the pairs (i from 0 to n-1 and j from i+1 to n-1) and calculated num[i] & num[j] and based on this formula: if (num & (num - 1)) is 0 then num is a power of 2. (seen this in kernighan's count of set bits), I've implemented. But out of 15 testcases, only 7 were passed and the other 8 were TLE.

Is there any better way to do both of these qns ???

Note: This is not for/from any OA (Online Assessment). This is just me trying to know some good methods to solve these types of questions .

Thanks in Advance

Comments (0)