Soft Skills
Soft Skills
Soft Skills
For example, assume the bill has the following prices: . Anna declines to eat item which costs . If Brian
calculates the bill correctly, Anna will pay . If he includes the cost of , he will calculate . In the second case, he
should refund to Anna.
Function Description
Complete the bonAppetit function in the editor below. It should print Bon Appetit if the bill is fairly split.
Otherwise, it should print the integer amount of money that Brian owes Anna.
• k: an integer representing the zero-based index of the item Anna doesn't eat
Input Format
The first line contains two space-separated integers and , the number of items ordered and the -based index
of the item that Anna did not eat.
The second line contains space-separated integers where .
The third line contains an integer, , the amount of money that Brian charged Anna for her share of the bill.
Constraints
Output Format
If Brian did not overcharge Anna, print Bon Appetit on a new line; otherwise, print the difference (i.e., ) that
Brian must refund to Anna. This will always be an integer.
Sample Input 0
41
3 10 2 9
12
Sample Output 0
Explanation 0
Anna didn't eat item , but she shared the rest of the items with Brian. The total cost of the shared items
is and, split in half, the cost per person is . Brian charged her for her portion of the bill. We print the amount
Anna was overcharged, , on a new line.
Sample Input 1
41
3 10 2 9
Sample Output 1
Bon Appetit
Explanation 1
Anna didn't eat item , but she shared the rest of the items with Brian. The total cost of the shared items
is and, split in half, the cost per person is . Because , we print Bon Appetit on a new line.
Submissions:
44
Max Score:
10
Difficulty:
Easy
More
Python 3
import math
import os
import random
import re
import sys
#
# The function accepts following parameters:
# 1. INTEGER_ARRAY bill
# 2. INTEGER k
# 3. INTEGER b
anna_share = total // 2
if anna_share == b:
print("Bon Appetit")
else:
print(b - anna_share)
if __name__ == '__main__':
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
k = int(first_multiple_input[1])
bonAppetit(bill, k, b)
2.
Louise joined a social networking site to stay in touch with her friends. The signup page required her to input
a name and a password. However, the password must be strong. The website considers a password to
be strong if it satisfies the following criteria:
• It contains at least one special character. The special characters are: !@#$%^&*()-+
She typed a random string of length in the password field but wasn't sure if it was strong. Given the string she
typed, can you find the minimum number of characters she must add to make her password strong?
Note: Here's the set of types of characters in a form you can paste in your solution:
numbers = "0123456789"
lower_case = "abcdefghijklmnopqrstuvwxyz"
upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
special_characters = "!@#$%^&*()-+"
Example
This password is 5 characters long and is missing an uppercase and a special character. The minimum number
of characters to add is .
This password is 5 characters long and has at least one of each character type. The minimum number of
characters to add is .
Function Description
Input Format
The second line contains the password string. Each character is either a lowercase/uppercase English
alphabet, a digit, or a special character.
Constraints
Sample Input 0
Ab1
Sample Output 0
Explanation 0
She can make the password strong by adding characters, for example, $hk, turning the password
into Ab1$hk which is strong.
Sample Input 1
11
#HackerRank
Sample Output 1
Explanation 1
The password isn't strong, but she can make it strong by adding a single digit.
Submissions:
41
Max Score:
10
Difficulty:
Easy
Rate This Challenge:
More
Python 3
#!/bin/python3
import math
import os
import random
import re
import sys
# 1. INTEGER n
# 2. STRING password
numbers = "0123456789"
lower_case = "abcdefghijklmnopqrstuvwxyz"
upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
special_characters = "!@#$%^&*()-+"
# Initialize flags for required character types
# Check each character in the password to see which types are present
if char in numbers:
has_digit = True
has_lower = True
has_upper = True
has_special = True
missing_types = 0
if not has_digit:
missing_types += 1
if not has_lower:
missing_types += 1
if not has_upper:
missing_types += 1
if not has_special:
missing_types += 1
# So we need either the missing types or enough characters to make the length 6
return max(missing_types, 6 - n)
if __name__ == '__main__':
print(minimumNumber(n, password))
3.
Dothraki are planning an attack to usurp King Robert's throne. King Robert learns of this conspiracy from
Raven and plans to lock the single door through which the enemy can enter his kingdom.
But, to lock the door he needs a key that is an anagram of a palindrome. He starts to go through his box of
strings, checking to see if they can be rearranged into a palindrome. Given a string, determine if it can be
rearranged into a palindrome. Return the string YES or NO.
Example
Function Description
Complete the gameOfThrones function below.
Returns
Input Format
Constraints
• |s|
Sample Input 0
aaabbbb
Sample Output 0
YES
Explanation 0
Sample Input 1
cdefghmnopqrstuvw
Sample Output 1
NO
Explanation 1
Palindromes longer than 1 character are made up of pairs of characters. There are none here.
Sample Input 2
cdcdcdcdeeeef
Sample Output 2
YES
Explanation 2
Submissions:
35
Max Score:
10
Difficulty:
Easy
More
Python 3
#!/bin/python3
import math
import os
import random
import re
import sys
def gameOfThrones(s):
freq = Counter(s)
# A string can be rearranged into a palindrome if there's at most one odd frequency
if odd_count > 1:
return "NO"
else:
return "YES"
if __name__ == '__main__':