We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Ok! I did the same mistake and implemented the same algorithm as you did. But you see, the problem is, from the given subset, if we take a nested loop for i and j
if ith value is 5:
jth value is 4: we get absolute difference as 1 ( increasing count by 1)
jth value is 6: we get absolute difference as 1 (increasing count by 1)
but the absolute difference between 4 and 6 ( since both are a part of our subarray, with atleast the wrong assumption that we made), is 2. which is wrong.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
Ok! I did the same mistake and implemented the same algorithm as you did. But you see, the problem is, from the given subset, if we take a nested loop for i and j if ith value is 5: jth value is 4: we get absolute difference as 1 ( increasing count by 1) jth value is 6: we get absolute difference as 1 (increasing count by 1)
but the absolute difference between 4 and 6 ( since both are a part of our subarray, with atleast the wrong assumption that we made), is 2. which is wrong.