Round 1
Questions:
-
Beauty of string
When John was a little kid he didn't have much to do. There was no internet, no Facebook, and no programs to hack on. So he did the only thing he could... he evaluated the beauty of strings in a quest to discover the most beautiful string in the world.
Given a string s, little Johnny defined the beauty of the string as the sum of the beauty of the letters in it. The beauty of each letter is an integer between 1 and 26, inclusive, and no two letters have the same beauty. Johnny doesn't care about whether letters are uppercase or lowercase, so that doesn't affect the beauty of a letter. (Uppercase 'F' is exactly as beautiful as lowercase 'f', for example.)
You're a student writing a report on the youth of this famous hacker. You found the string that Johnny considered most beautiful. What is the maximum possible beauty of this string?
Input:
Your program should read lines from standard input. Each line is a string.
Output:
Print out the maximum beauty for the string.
Test 1 Input: ABbCcc
Expected Test 1 Output: 152
Test 2 Input: Ignore punctuation, please :)
Expected Test 2 Output: 491 -
Calculate sum excluding multiples of 5 and 7
Write a program that, given an integer N, sums all the whole numbers from 1 through N (both inclusive). Do not include in your sum any of the intermediate values (1 and N inclusive) that are divisible by 5 or 7.
Input:
Your program should read lines from standard input. Each line contains a positive integer.
Output:
For each line of input, print to standard output the sum of the integers from 1 through n, disregarding those divisible by 5 and 7. Print out each result on a new line.
Test 1 Input: 10
Expected Output: 33
Candidate's Approach
For the first question, the approach involves:
- Converting the string to lowercase to handle case insensitivity.
- Assigning beauty values to each unique letter starting from 26 down to 1.
- Summing the beauty values of the letters present in the string.
For the second question:
- Looping through numbers from 1 to N.
- Checking if each number is divisible by 5 or 7.
- Summing only those numbers that are not divisible by 5 or 7.
Interviewer's Feedback
No feedback provided.