silentknight00's blog

By silentknight00, history, 4 years ago, In English

Problem Statement Given a list of array of numbers A,pick the smallest non-negative (≥ 0) then decreases each number of the array by the index of the selected number. This constitutes as one operation. What is the minimum number of operations to do till all become less than 0? Constraint 1<=Size of Array<=100 1<=Each Element<=1000

I was thinking of the following approach. Store the element's index in an array of size 100x1000(to handle duplicates) Sort the original array. (Nlogn) Iterate over the array with a pointer and maintain a sum of indexes so far and i) check if the current pointer has element less than 0 if yes then move on else ans+=1 and sum of index+=index of the current number(original index)

Is this optimized space and time complexity wise?

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it

By silentknight00, history, 6 years ago, In English

The Problem Statement is :

Bob is given a string. But Bob only likes palindromes, and now wants to partition the string into palindromes. However, after his friends told him his demands are simply exorbitant, Bob has chosen to relax his conditions. He has agreed to rearranging the partitions himself to make palindromes, so is now looking to partition the string into such ’possible’ palindromes. As always, help Bob to find the minimum partitions needed for his demand to be met.

Sample TestCase

Input — aabxyyzz Output-2

Explanation:The string can be partitioned as aab | xyyzz, since these partitions can bere-arranged to aba, yzxzy, both of which are palindromes

Input — abcdefghijklmnopqrstuvwxyz Output-26

Can any explain how one should approach such problems?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By silentknight00, history, 6 years ago, In English

Given an array [1,3,4,2] we should get an array [0,0,0,2]. Can someone suggest a quick method for doing this

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it