We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #79: Passcode derivation

Project Euler #79: Passcode derivation

Problem
Submissions
Leaderboard
Discussions

This problem is a programming version of Problem 79 from projecteuler.net

A common security method used for online banking is to ask the user for three random characters from a passcode. For example, if the passcode was , they may ask for the , , and characters; the expected reply would be: .

Given that the three characters are always asked for in order, analyse the file so as to determine the shortest possible secret passcode of unknown length.

Assume all characters in your password are different. You're given successful login attempts each containing characters with ASCII codes from to both inclusive. You need to recover the shortest original password possible. If there are multiple choices, select the lexicographically smallest one.

If something went wrong and the original password cannot be recovered,
output SMTH WRONG.

Constraints

Sample Input 1

5
SMH
TON
RNG
WRO
THG

Sample Output 1

SMTHWRONG

Sample Input 2

3
an0
n/.
.#a

Sample Output 2

SMTH WRONG

Explanation

As you can see, there is a unique shortest password in the first test case, namely, "SMTHWRONG" (why not?).
Let's look at the second case. We see that 'a' comes before 'n' (first attempt), then 'n' comes before '.' (second attempt) and '.' comes before 'a' (third attempt). But 'a' cannot come before 'a' as all characters must be different.

Author

shashank21j

Difficulty

Hard

Max Score

100

Submitted By

1629

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy