Problem: Given a T9-style string (like on feature phones), decode it using custom logic.
'a', 'd', 'g', 'p'),"aback" → "cat""pp" → "pp""abcd" → "ad""pqrsatm" → "sam""ppqrammnod" → "pramod"function decodeT9Input(input) {
const t9Groups = {
'2': 'abc', '3': 'def', '4': 'ghi',
'5': 'jkl', '6': 'mno', '7': 'pqrs',
'8': 'tuv', '9': 'wxyz'
};
const startingChars = new Set();
for (let key in t9Groups) {
startingChars.add(t9Groups[key][0]);
}
let result = '';
for (let i = 1; i < input.length; i++) {
if (startingChars.has(input[i])) {
result += input[i - 1];
}
}
return result;
}Problem: Check if a number is a palindrome, without using .reverse() or string helpers.
function isPalindrome(num) {
let original = num;
let reversed = 0;
while (num > 0) {
reversed = reversed * 10 + num % 10;
num = Math.floor(num / 10);
}
return original === reversed;
}function isPalindrome(n, r = 0) {
for (let x = n; x; x = ~~(x / 10)) r = r * 10 + x % 10;
return n === r;
}Unified version that handles both strings and numbers:
function isPalindrome(input) {
const str = input.toString();
let left = 0, right = str.length - 1;
while (left < right) {
if (str[left++] !== str[right--]) return false;
}
return true;
}Q: Java 8 allows default methods in interfaces — so do we still need abstract classes?
Yes, abstract classes are still needed for:
protected/privateUse interface when multiple inheritance or contracts are needed.
Use abstract class when common base logic or shared config is needed.
“I used interfaces for extensibility in platform components and abstract classes for shared behavior like audit logging and retry logic.”
Q: What is a callback?
A callback is a function passed as an argument to another function, to be executed later.
Commonly used in:
setTimeout, APIs)In real projects, I used it to handle fetch results or execute steps after background jobs.
Got the call for HM Round -> Link