IBM Coding Questions 2023 | IBM software developer coding questions 2024 | IBM programming test questions: If anyone have IBM exam for the role of Software Engineer or Software Developer and you are looking for previous year question or this year question for your practice then you are on the right place.
Here you will get the IBM Coding question with solution or IBM coding questions with answers. we have added question image below.
Join Telegram Channel (43,230 Member)IBM Latest Interview Experience: Check here
Question 1: Which was asked in IBM Software Developer coding exam round
Subscribe Here For Daily Job Update:👇
Question 2: IBM Software Developer coding questions for practice
Given in request ids as an array of strings, requests, and an integer k, after all requests are received, find the & most recent requests. Report the answer in order of most recent to least recent,
Example:
Suppose n5, requests [item1″, “item2”, “item3”, “item1”, “item 31 and k=3
Starting from the right and moving left, collecting distinct requests, there is “Item3” followed by “item1” Skip the second instance of “item3” and find “item2”. The answer is [“item3”, “item1”, “item2]
Function Description Complete the function getLatestRequests in the editor below.
getLatest Requests takes the following arguments:
str requests/n): the request ids
int &: the number of requests to report
Returns:
strik: the k most recent requests
Constraints:
- 1<k<n<10^5
-requests consists of lowercase characters and digits only (a-z,0-9)
Input Format For Custom Testing:
The first line contains an integer, n the number of elements in requests.
Each of the next n lines contains a string, requests[i].
The next line contains an integer, k
Solution:
import java.util.*;
public class RecentRequests {
public static List<String> getLatestRequests(String[] requests, int k) {
LinkedHashMap<String, Boolean> recentRequests = new LinkedHashMap<>();
// Iterate through the requests in reverse order
for (int i = requests.length - 1; i >= 0; i--) {
String request = requests[i];
// Add the request to the LinkedHashMap (ignores duplicates)
recentRequests.put(request, true);
// Break if k distinct requests are found
if (recentRequests.size() == k) {
break;
}
}
// Return the keys of the LinkedHashMap in the correct order (most recent to least recent)
List<String> result = new ArrayList<>(recentRequests.keySet());
Collections.reverse(result);
return result;
}
public static void main(String[] args) {
int n = 5;
String[] requests = {"item1", "item2", "item3", "item1", "item3"};
int k = 3;
List<String> result = getLatestRequests(requests, k);
System.out.println(result);
}
}
Check Out Other IBM Coding Questions 2023
- IBM Software Developer coding questions: Click Here
- IBM Test question & Answer: Click Here
For More IBM Coding Question Join us:
Join Telegram (Must) | Click Here |
Subscribe Youtube channel | Click Here |
Join Experienced Job Telegram | Click Here |
Follow Instagram Job Page Link: | Join Here |