IBM coding questions with answers 2023 2024 | IBM hackerrank coding questions : If you are looking for IBM previous year question or this year then you land on right page. Check below IBM Coding question which was asked in November 2023 Exam.
Problem Statement:
When we share our phone numbers with others, we share the numbers digit by digit.
Given a phone number in words, convert the number to digits.
For example, convert “six four eight three” to “6483”.
- All phone numbers will be 10 digits.
- Two repeating digits will be shortened using the word “double”. Three repeating
digits will be shortened using the word “triple”. If the digits repeat four or more
times, they will be shortered using ‘double’ and ‘triple’ mutiple times.
Check Other IBM Question Here: Question Link
IBM Latest Interview Experience: Check here
Solution:
// Tech program mind
// Use this editor to write, compile and run your Java code online
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String str = sc.nextLine();
String [] arr = str.split(" ");
String ans = "";
int i=0;
HashMap wordToDigitMap = new HasMap<>();
wordToDigitMap.put("zero", "0");
wordToDigitMap.put("one", "1");
wordToDigitMap.put("two", "2");
wordToDigitMap.put("three", "3");
wordToDigitMap.put("four", "4");
wordToDigitMap.put("five", "5");
wordToDigitMap.put("six", "6");
wordToDigitMap.put("seven", "7");
wordToDigitMap.put("eight", "8");
wordToDigitMap.put("nine", "9");
while(i<arr.length){
if(arr[i].equals("double")){
ans= ans+wordToDigitMap.get(arr[i+1]) + wordToDigitMap.get(arr[i+1]);
i++;
}
else if(arr[i].equals("triple")){
ans= ans+wordToDigitMap.get(arr[i+1]) + wordToDigitMap.get(arr[i+1]) + wordToDigitMap.get(arr[i+1]);
i++;
}
else {
ans= ans+wordToDigitMap.get(arr[i]);
}
i++;
}
System.out.print(ans);
}
}
IBM Code Explanation YouTube Video:
For More IBM Coding Question Join us:
Join Telegram (Must) | Click Here |
Join Experienced Job Telegram | Click Here |
Follow Instagram Job Page Link: | Join Here |