Viva Questions
Viva Questions
Anagram Checker
Sample Input/Output:
Input: "listen", "silent"
Output: true
Sample Input/Output:
Input: arr = [1, 2, 1, 3, 4, 2, 3], k = 4
Output: [3, 4, 4, 3]
Explanation:
Window [1, 2, 1, 3] has 3 distinct numbers.
Window [2, 1, 3, 4] has 4 distinct numbers.
...
Sample Input/Output:
Input: arr = [2, 7, 11, 15], target = 9
Output: [0, 1] (since arr[0] + arr[1] = 2 + 7 = 9)
3. Employee Department Mapping
Sample Input/Output:
Input: Add Alice in HR, Bob in IT, Eve in IT
Output: Employees in IT: [Bob, Eve]
Sample Input/Output:
Input: Alice - 85, Bob - 90, Charlie - 75
Output: Bob: 1st, Alice: 2nd, Charlie: 3rd
Sample Input/Output:
Input: arr1 = [1, 2, 2, 3], arr2 = [2, 2, 4, 5]
Output: [2, 2]
Sample Input/Output:
Input: {Alice=85, Bob=90, Charlie=75}
Output: {Charlie=75, Alice=85, Bob=90} // sorted by value
Sample Input/Output:
Input: map1 = {Alice=85, Bob=90}, map2 = {Alice=85, Bob=90}
Output: true
7 Frequency of Characters
Problem: Write a Java program that takes a string as input and uses a
HashMap to count the frequency of each character in the string. Ignore
spaces.
Sample Input/Output:
Input: "hello world"
Output: {h=1, e=1, l=3, o=2, w=1, r=1, d=1}
Sample Input/Output:
Input: [1, 2, 3, 1, 4, 5, 2]
Output: [1, 2]
9 Word Count in a Sentence
Sample Input/Output:
Input: "Java is fun and Java is powerful"
Output: {java=2, is=2, fun=1, and=1, powerful=1}