calculus.saransh's blog

By calculus.saransh, 10 years ago, In English

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.
 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Question A

If 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.

  • »
    »
    22 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank You.

  • »
    »
    5 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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 .

»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How to take input of string in A.??

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

    • »
      »
      »
      13 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      What if input characters are unknowingly long and I don't wanna declare my string size near as 10^9??any optimized method??

      • »
        »
        »
        »
        5 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        declare string using string keyword as "string str" and take it as cin>> he said it.