peroooo's blog

By peroooo, 2 months ago, In English

Question 1:- You are given a string of numbers, You have to return a partitioned String Array in which substring (i-1)th +(i-2)th = ith substring. If not possible return an empty string array. For example: Input: Output: "111122335" ------> {"1","11","12","23","35"}
Input: Output: "112233" -------> {"11","22","33"} Input: Output: "11314" -------> {"11","3","14"} or {"1","13","14"} Input: Output: "13234113" -------->{}

Link:- https://www.geeksforgeeks.org/partition-given-string-manner-ith-substring-sum-1th-2th-substring/

So I gave a Backtracking solution(same as the given link) for the first question. but he asked me to improve the time complexity for the solution is there any better approach to solve this problem really can't think of anything else than backtracking.

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