### calculus.saransh's blog

By calculus.saransh, 11 years ago,

Question A

This was a straight forward question which required the checking of "0000000" or "1111111" as a substring contained in the given string. Java implementation allows the use of str.contains() function which makes the code very short.

Question B

This question could be solved by brute force considering the small constraints for this question. Keeping a recursive method which takes the temporary number created till now the count of fours and sevens and global variable which stores the answer can help us solve the question with ease.

Question C

Again a straight forward implementation. Some of the things to note. If the string contains the substrings all characters of that substring have to be replaced. Hence we replace with the favorite char but if the favorite char is already there we replace with 'A' or 'a' because that happens to be lexographically smallest. Corner case- Favorite char is 'A' , if yes.. if 'A' is present as a part of substring replacement is done by 'B'.

Question D

Some of the things which I did not take note of during the competition which prevented my solution from passing. Use adjacency list instead of matrix as the number of roads are only 1000. The question says that there can be multiple roads between junctions so updation needs to be done to adj[s][e] when a lower distance comes up.

Approach

A combination of djikstra and DFS allows us to find the minimum cost incurred in traversing the points. Update your djikstra cost array at all nodes which can be visited from the taxi you are in. This can be done using DFS. Again find the minimum cost junction and continue. If at the end you are not able to reach the destination output should be -1.

• +5

 » 4 years ago, # |   0 Question AIf you using cpp, then one can also use 'std::string.find("string to find")!=std::string::npos' as condition in the 'if' block as a check.
•  » » 3 years ago, # ^ |   0 Thank You.
•  » » 20 months ago, # ^ |   0 thankyou for simpleParadox for your easy suggestion i am stuck nearly 10-15 minutes then i saw your suggestion on comment box and implement it and my code get accepted .
 » 2 years ago, # |   0 How to take input of string in A.??
•  » » 2 years ago, # ^ |   0 if you use cpp then you can declare string using string keyword as "string str" and take it as cin>> or declare string as " int str[100] " and take it by %s
•  » » » 2 years ago, # ^ |   0 What if input characters are unknowingly long and I don't wanna declare my string size near as 10^9??any optimized method??
•  » » » » 20 months ago, # ^ |   0 declare string using string keyword as "string str" and take it as cin>> he said it.
 » 13 months ago, # |   0 Question AIn Python we can use the in keyword: p = input() print("YES" if "1111111" in p or "0000000" in p else "NO") 
•  » » 4 months ago, # ^ |   0 yes you can