You are not logged in. Please login at www.codechef.com to post your questions!

×

help needed in hackerrank problem

Can someone please help me with this problem. Thanks in advance.

asked 05 Apr '18, 00:33

pavitra_ag's gravatar image

4★pavitra_ag
696
accept rate: 5%


try to do it backwards. First convert the string into the encrypted code. Then just start from last and at every step you have two choices either to take the current digit only or (if possible i.e. <=26) then take the current and previous digit and corresponding merge it with appropraite position.

We maintain a vector of string for each index which denotes 'What is the different string we can get if we start from current position'. So, let's suppose you are building the answer for position 'i' (means you have the answers for all the indexes 'j' : (i < j <= n-1)). So, at current place you have two choices i.e. either take current position digit only and form a string with the remaining digits (i.e. from [i+1, n-1]) (for doing that we have to just merge the current character with the vector of index 'j+1'). Or we can take next digit also and check it's possibility (i.e. <= 26) and at that time we have to just merge that character with the list of strings of index 'j+2'.

And we have to just print the list of index '0'. And we are done! Don't forget to sort it before printing!

link

answered 05 Apr '18, 08:35

pk301's gravatar image

2★pk301
62710
accept rate: 16%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×349
×310
×181

question asked: 05 Apr '18, 00:33

question was seen: 167 times

last updated: 05 Apr '18, 08:35