This is a verified interview question from Walmart-sde. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Public and Private Keys" covers key patterns like Other.
"IIT BHU Jerome and his friend Martin have developed a special app for sending messages. The app has a special feature of encryption. So, whenever Jerome wants to send the message to Martin an encrypted message, they must need the public and private keys. To get the public and private key they have decided to choose three integers P, R, and a secret code X, and use the following rules to generate both the keys The rules are: The public key will be the smallest integer N for which P ≤ N ≤ R and the sum of its digits is X. The private key will be the largest integer M for which P ≤ M ≤ R and the sum of its digits is X. Jerome and Martin will be able to send and receive the encrypted messages successfully only if correctly determines numbers i.e., public key N and private key M remembering that the N and M will always exist. Can you help Jerome and his friend Martin with a program to generate the public and private keys by accepting P, R, and X. Read the input from STDIN and print the output to STDOUT. Do not write arbitrary strings while reading the input or while printing, as these contribute to the standard output."
Join thousands of developers practicing for Walmart-sde.