ApplicateAI Coding Questions And Answers
ApplicateAI Coding Questions with Solutions
ApplicateAI Coding Questions and Answers page will help you to get sample Coding Questions asked in the Online Selection Process of ApplicateAI.
Go through this page to get all Sample ApplicateAI Coding Questions for preparing for Online Assessments and Technical Interviews of the same.
Practice ApplicateAI Coding Questions and Answers
Question 1
Problem Statement :
You’re given a string, you’ve to print additional characters needed to make that string a palindrome.
A Palindrome is a sequence of characters that has the property of reading the same in either direction.
Input :
abede
Output :
ba
Sample Input :
abcfe
Sample output :
fcba
import java.util.*; public class Main { public static boolean isPalindrome(String str) { char arr[] = str.toCharArray(); for (int i = 0, j = arr.length - 1; i < j; i++, j--) if (arr[i] != arr[j]) return false; return true; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); String res = ""; for (int i = 0; i < str.length(); i++) { if (isPalindrome(str.substring(i, str.length()))) { res = str.substring(0, i); break; } } System.out.println(new StringBuilder(res).reverse()); } }
Question 2
A taxi can take multiple passengers to the railway station at the same time.On the way back to the starting point,the taxi driver may pick up additional passengers for his next trip to the airport.A map of passenger location has been created,represented as a square matrix.
The Matrix is filled with cells,and each cell will have an initial value as follows:
- A value greater than or equal to zero represents a path.
- A value equal to 1 represents a passenger.
- A value equal to -1 represents an obstruction.
The rules of motion of taxi are as follows:
- The Taxi driver starts at (0,0) and the railway station is at (n-1,n-1).Movement towards the railway station is right or down,through valid path cells.
- After reaching (n-1,n-1) the taxi driver travels back to (0,0) by travelling left or up through valid path cells.
- When passing through a path cell containing a passenger,the passenger is picked up.once the rider is picked up the cell becomes an empty path cell.
- If there is no valid path between (0,0) and (n-1,n-1),then no passenger can be picked.
- The goal is to collect as many passengers as possible so that the driver can maximize his earnings.
For example consider the following grid,
0 1
-1 0
Start at top left corner.Move right one collecting a passenger. Move down one to the destination.Cell (1,0) is blocked,So the return path is the reverse of the path to the airport.All Paths have been explored and one passenger is collected.
Returns:
- Int:maximum number of passengers that can be collected.
Sample Input 0
- 4 -> size n = 4
- 4 -> size m = 4
- 0 0 0 1 -> mat
- 1 0 0 0
- 0 0 0 0
- 0 0 0 0
Output 0
- 2
Explanation 0
The driver can contain a maximum of 2 passengers by taking the following path
(0,0) → (0,1) → (0,2) → (0,3) → (1,3) → (2,3) → (3,3) → (3,2) → (3,1) → (3,0) → (2,0) → (1,0) → (0,0)
Sample Input 1
STD IN Function
———— ————-
- 3 → size n=3
- 3 → size m=3
- 0 1 -1 → mat
- 1 0 -1
- 1 1 1
Sample Output 1
- 5
Explanation 1
The driver can contain a maximum of 5 passengers by taking the following path
(0,0) → (0,1) → (1,1) → (2,1) → (2,2) → (2,1) → (2,0) → (1,0) → (0,0)
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
import java.util.*; class Main { public static int cost(int grid[][], int row1, int col1, int row2, int col2) { if (row1 == row2 && col1 == col2) { if (grid[row1][col1] == 1) return 1; return 0; } int ans = 0; if (grid[row1][col1] == 1) ans++; if (grid[row2][col2] == 1) ans++; return ans; } public static int solve(int n, int m, int grid[][], int dp[][][], int row1, int col1, int row2) { int col2 = (row1 + col1) - (row2); if (row1 == n - 1 && col1 == m - 1 && row2 == n - 1 && col2 == m - 1) return 0; if (row1 >= n || col1 >= m || row2 >= n || col2 >= m) return -1 * Integer.MAX_VALUE; if (dp[row1][col1][row2] != -1) return dp[row1][col1][row2]; int ch1 = -1 * Integer.MAX_VALUE, ch2 = -1 * Integer.MAX_VALUE; int ch3 = -1 * Integer.MAX_VALUE, ch4 = -1 * Integer.MAX_VALUE; if (grid[row1][col1 + 1] != -1 && grid[row2 + 1][col2] != -1) ch1 = cost(grid, row1, col1 + 1, row2 + 1, col2) + solve(n, m, grid, dp, row1, col1 + 1, row2 + 1); if (grid[row1][col1 + 1] != -1 && grid[row2][col2 + 1] != -1) ch2 = cost(grid, row1, col1 + 1, row2, col2 + 1) + solve(n, m, grid, dp, row1, col1 + 1, row2); if (grid[row1 + 1][col1] != -1 && grid[row2][col2 + 1] != -1) ch3 = cost(grid, row1 + 1, col1, row2, col2 + 1) + solve(n, m, grid, dp, row1 + 1, col1, row2); if (grid[row1 + 1][col1] != -1 && grid[row2 + 1][col2] != -1) ch4 = cost(grid, row1 + 1, col1, row2 + 1, col2) + solve(n, m, grid, dp, row1 + 1, col1, row2 + 1); return dp[row1][col1][row2] = Math.max(ch1, Math.max(ch2, Math.max(ch3, ch4))); } public static void initializeDp(int dp[][][], int item) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) for (int k = 0; k < 5; k++) dp[i][j][k] = item; } } public static int collectMax(int n, int m, int grid[][]) { int ans = 0; int dp[][][] = new int[6][6][6]; initializeDp(dp, -1); if (grid[n - 1][m - 1] == -1 || grid[0][0] == -1) ans = -1 * Integer.MAX_VALUE; if (grid[0][0] == 1) ans++; grid[0][0] = 0; if (grid[n - 1][m - 1] == 1) ans++; grid[n - 1][m - 1] = 0; ans += solve(n, m, grid, dp, 0, 0, 0); return Math.max(ans, 0); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int arr[][] = new int[n + 1][m + 1]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) arr[i][j] = sc.nextInt(); System.out.println(collectMax(n, m, arr)); } }
Question 3
Problem Statement :
You are given an array, You have to choose a contiguous subarray of length ‘k’, and find the minimum of that segment, return the maximum of those minimums.
Sample input :
1 → Length of segment x =1
5 → size of space n = 5
1 → space = [ 1,2,3,1,2]
2
3
1
2
Sample output :
3
Explanation :
The subarrays of size x = 1 are [1],[2],[3],[1], and [2],Because each subarray only contains 1 element, each value is minimal with respect to the subarray it is in. The maximum of these values is 3. Therefore, the answer is 3
import java.util.*; public class DiskSpace { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i < n;i++) arr[i]=sc.nextInt(); int min=Integer.MAX_VALUE; int max=Integer.MIN_VALUE; for(int i=0;i <= n-x;i++) { min=Integer.MAX_VALUE; for(int j=i;j < (i+x);j++) min=Math.min(min,arr[j]); max=Math.max(min,max); } System.out.println(max); } }
Question 4
Problem Statement -:
In an airport, the Airport authority decides to charge a minimum amount to the passengers who are carrying luggage with them. They set a threshold weight value, say, T, if the luggage exceeds the weight threshold you should pay double the base amount. If it is less than or equal to threshold then you have to pay $1.
Function Description:
Complete the weightMachine function in the editor below. It has the following parameter(s):
Parameters:
Name | Type | Description |
N | Integer | number of luggage |
T | Integer | weight of each luggage |
weights[ ] | Integer array | threshold weight |
Returns: The function must return an INTEGER denoting the required amount to be paid.
Constraints:
- 1 <= N <= 10^5
- 1 <= weights[i] <= 10^5
- 1 <= T <= 10^5
Input Format for Custom Testing:
- The first line contains an integer, N, denoting the number of luggage.
- Each line i of the N subsequent lines (where 0 <= i <n) contains an integer describing the weight of ith luggage.
- The next line contains an integer, T, denoting the threshold weight of the boundary wall.
Sample Cases:
- Sample Input 1
4
1
2
3
4
3 - Sample Output 1
5 - Explanation:
Here all weights are less than threshold weight except the luggage with weight 4 (at index 3) so all pays base fare and it pays double fare.
import java.util.*; class Main { static int weightMachine (int N, int weights[],int T) { int amount = 0, i; for (i = 0; i < N; i++) { amount++; if (weights[i] > T) { amount++; } } return amount; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt (); int weights[]= new int[n]; for(int i=0; i<n; i++) weights[i] = sc.nextInt(); int t = sc.nextInt (); System.out.println (weightMachine(n, weights, t)); } }
Question 5:
Given two strings, s, and sub, along with a 2D character array mappings, we want to determine if it is possible to make the sub a substring of s by replacing characters according to the provided mappings. Each mapping consists of a pair [oldi, newi], indicating that we can replace the character oldi in sub with newi.
The replacement can be performed any number of times, but each character in sub can be replaced at most once.
We need to return true if it is possible to create sub as a substring of s using the given replacements, and false otherwise.
Example 1:
Input:
s = “fool3e7bar”
sub = “leet”
mappings = [[“e”,”3″],[“t”,”7″],[“t”,”8″]]
Output: True
Explanation:
We replace the first occurrence of ‘e’ in sub with ‘3’ and ‘t’ in sub with ‘7’, resulting in sub becoming “l3e7”. Now, “l3e7” is a substring of s, so we return true.
Example 2:
Input:
s = “fooleetbar”
sub = “f00l”
mappings = [[“o”,”0″]]
Output: False
Explanation:
The string “f00l” is not a substring of s, and no replacements can be made to create it. Additionally, we cannot replace ‘0’ with ‘o’, so it is not possible to create sub from s. Hence, we return false.
Example 3:
Input:
s = “Fool33tbaR”
sub = “leetd”
mappings = [[“e”,”3″],[“t”,”7″],[“t”,”8″],[“d”,”b”],[“p”,”b”]]
Output: True
Explanation:
We replace the first and second occurrences of ‘e’ in sub with ‘3’ and ‘d’ in sub with ‘b’, respectively. This transforms sub into “l33tb”, which is a substring of s. Therefore, we return true.
Constraints:
1 <= sub.length <= s.length <= 5000
0 <= mappings.length <= 1000
mappings[i].length == 2
oldi != newi
Both s and sub consist of uppercase and lowercase English letters and digits.
oldi and newi are either uppercase or lowercase English letters or digits.
class Main { public boolean matchReplacement(String s, String sub, char[][] mappings) { int m = sub.length(), n = s.length(); final int RANGE = 'z' - '0' + 1; boolean[][] multiMap = new boolean[RANGE][RANGE]; for (char[] map : mappings) { char from = map[0], to = map[1]; multiMap[from - '0'][to - '0'] = true; } // Now, we use a naive string matching algorithm // This will run in O(mn) time. for (int i = 0; i < n - m + 1; i++) { int j = 0; while (j < m) { char sc = s.charAt(i + j), subc = sub.charAt(j); if (sc != subc && !multiMap[subc - '0'][sc - '0']) break; j++; } if (j == m) return true; } return false; } public static void main(String[] args) { Main main = new Main(); // Example usage: // String s = "fool3e7bar"; // String sub = "leet"; // char[][] mappings = { { 'e', '3' }, { 't', '7' }, { 't', '8' } }; // String s = "fooleetbar"; // String sub = "f00l"; // char[][] mappings = { { 'o', '0' } }; String s = "Fool33tbaR"; String sub = "leetd"; char[][] mappings = { { 'e', '3' }, { 't', '7' }, { 't', '8' }, { 'd', 'b' }, { 'p', 'b' } }; boolean result = main.matchReplacement(s, sub, mappings); System.out.println(result); // Output: true } }
Question 6 :
Problem statement :
Stephan is a vampire. And he is fighting with his brother Damon. Vampires get energy from human bloods, so they need to feed on human blood, killing the human beings. Stephan is also less inhuman, so he will like to take less life in his hand. Now all the people’s blood has some power, which increases the powers of the Vampire. Stephan just needs to be more powerful than Damon, killing the least human possible. Tell the total power Stephan will have after drinking the bloods before the battle.
Note that: Damon is a beast, so no human being will be left after Damon drinks everyone’s blood. But Stephan always comes early in the town.
Input Format :
First line with the number of people in the town, n.
Second line with a string with n characters, denoting the one digit power in every blood.
Output Format :
Total minimum power Stephan will gather before the battle.
Constraints :
n<=10^4
Sample input :
6
093212
Sample output:
9
Explanation :
Stephan riches the town, drinks the blood with power 9. Now Damon cannot reach 9 by drinking all the other bloods.
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String str = sc.next(); char arr[] = str.toCharArray(); int a[] = new int[arr.length]; for (int i = 0; i < a.length; i++) a[i] = Integer.parseInt(arr[i] + ""); Arrays.sort(a); int sum = 0; for (int i = 0; i < a.length; i++) sum = sum + a[i]; int sumA = 0; int sumB = sum; ArrayList < Integer > subsetA = new ArrayList < Integer > (); for (int i = a.length - 1; i >= 0; i--) { sumA = sumA + a[i]; sumB = sumB - a[i]; subsetA.add(a[i]); if (sumA > sumB) break; } Iterator itr = subsetA.iterator(); while (itr.hasNext()) { System.out.print((Integer) itr.next()); } } }
Question 7:
Problem Statement :
Suppose you are in a number system, where if the number doesn’t contain 2 in the unit digit then the number is not valid. So the first number of the number system is 2, the second number is 12, and the third is 22.
for a given integer n, you have to print the nth element of the number system.
Input Format:
First line, containing n denoting the number of test cases.
then n number of lines for the query.
Output Format:
Print the consecutive number in the number system for each query.
Sample Input:
3
Sample Output:
22
Explanation:
1st number will be 2 , 2nd number will be 12 and third number will be 32
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); System.out.println((n - 1) * 10 + 2); } }
Question 8:
Problem Statement :
Ratan is a crazy rich person. And he is blessed with luck, so he always made the best profit possible with the shares he bought. That means he bought a share at a low price and sold it at a high price to maximize his profit. Now you are an income tax officer and you need to calculate the profit he made with the given values of stock prices each day. You have to calculate only the maximum profit Ratan earned.
Note that:
Ratan never goes into loss.
Example 1 :
Price=[1,6,2]
Ratan buys it on the first day and sells it on the second.
Example 2 :
Price=[9,8,6]
The Price always went down, Ratan never bought it.
Input Format:
First line with an integer n, denoting the number days with the value of the stack
Next n days, telling the price of the stock on that very day.
Output Format:
Maximum profit done by Ratan in a single line.
Constraints:
Number of days <=10^8
Sample Input for Custom Testing:
STDIN
7
1
9
2
11
1
9
2
Sample Output :
10
Explanation :
The maximum profit possible is when Ratan buys it in 1 rupees and sells it in 11.
import java.util.*; public class PrepInsta { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int price[] = new int[n]; for(int i=0;i < n;i++) { price[i] = sc.nextInt(); } Vector < Integer > diff = new Vector<>(); for(int i=n-2;i >=0;i--) { diff.add(price[i+1]-price[i]); } int ans = solve(diff); if(ans < 0) { System.out.println(0); }else { System.out.println(ans); } } private static int solve(Vector < Integer > v) { int n = v.size(); if(n==0) { return 0; } int mx = v.get(0); for(int i=1;i < n;i++) { mx = Math.max(mx, v.get(i)); } if(mx <= 0) { return 0; } int mxSum=0,csum=0; for(int i=0;i < n;i++) { csum+=v.get(i); if(csum < 0) csum=0; mxSum = Math.max(csum, mxSum); } return mxSum; } }
Question 9:
Problem Statement :
A company has a list of jobs to perform. Each job has a start time, end time and profit value. The manager has asked his employee Anirudh to pick jobs of his choice. Anirudh being greedy wants to select jobs for him in such a way that would maximize his earnings.
Given a list of jobs how many jobs and total earning are left for other employees once Anirudh
Picks jobs of his choice.
Note: Anirudh can perform only one job at a time.
Input format:
Each Job has 3 pieces of info – Start Time,End Time and Profit
The first line contains the number of Jobs for the day. Say ‘n’. So there will be ‘3n lines
following as each job has 3 lines.
Each of the next ‘3n’ lines contains jobs in the following format:
start_time
end-time
Profit
start-time and end-time are in HHMM 24HRS format
i.e. 9am is 0900 and 9PM is 2100
Constraints :
The number of jobs in the day i.e’ is less.
than 10000
0<_n<_10000
start-time is always less than end time.
Output format :
Program should return an array of 2 integers where
1st one is number of jobs left and earnings of other employees
Sample Input 1 :
4
0200
0300
10
0400
0700
20
0300
0800
30
0900
1000
50
Sample Output 1:
1
20
Sample Explanation 1
CHooses 1st, 3rd and 4th job cause they don’t overlap. So only second job is remaining.
Sample Input 2:
5
0805
0830
100
0835
0900
100
0905
0930
100
0935
1000
100
1005
1030
100
Sample output 2:
0
0
Sample Explanation 2:
Anirudh can work on all appointments as there are none overlapping.
Hence 0 appointments and 0 earnings for other employees.
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; class Job { public Integer st; public Integer ed; public Integer cost; public Job() { super(); } public Job(Integer st, Integer ed, Integer cost) { super(); this.st = st; this.ed = ed; this.cost = cost; } } class Pair { public Integer first; public Integer second; public Pair() { super(); } public Pair(Integer first, Integer second) { super(); this.first = first; this.second = second; } } class SortingJobs implements Comparator < Job > { @Override public int compare(Job o1, Job o2) { if (o1.ed < o2.ed) { return 1; } else { return 0; } } } public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Job[] arr = new Job[n]; int cost; String st, ed; int total = 0; for (int i = 0; i < n; i++) { st = sc.next(); ed = sc.next(); if (st.length() < 4) { while (st.length() != 4) { st += "0"; } } if (ed.length() < 4) { while (ed.length() != 4) { ed += "0"; } } cost = sc.nextInt(); arr[i] = new Job(); arr[i].st = getTime(st); arr[i].ed = getTime(ed); arr[i].cost = cost; total += cost; } Arrays.sort(arr, new SortingJobs()); Pair res = new Pair(); res = solve(arr, n); if (res == null) { System.out.println(0); } else { System.out.println(n - res.first); System.out.println(total - res.second); } } private static Pair solve(Job[] arr, int n) { if (n == 0) { return null; } int dp[] = new int[n]; int numOfJobs[] = new int[n]; for (int i = 0; i < n; i++) { dp[i] = 0; numOfJobs[i] = 0; } dp[0] = arr[0].cost; numOfJobs[0] = 1; for (int i = 1; i < n; i++) { int curr = arr[i].cost; int num = 1; int idx = searchJob(arr, 0, i - 1, arr[i].st); if (idx != curr && idx != -1) { curr += dp[idx]; num += numOfJobs[idx]; } if (curr > dp[i - 1]) { dp[i] = curr; numOfJobs[i] = num; } else { dp[i] = dp[i - 1]; numOfJobs[i] = numOfJobs[i - 1]; } } return new Pair(numOfJobs[n - 1], dp[n - 1]); } private static int searchJob(Job[] arr, int st, int ed, int key) { int ans = -1; while (st <= ed) { int mid = (st + ed) / 2; if (arr[mid].ed <= key) { ans = mid; st = mid + 1; } else { ed = mid - 1; } } return ans; } private static int getTime(String st) { int hr = (st.charAt(0) - '0') * 10 + (st.charAt(1) - '0'); int min = (st.charAt(2) - '0') * 10 + (st.charAt(3) - '0'); return hr * 60 + min; } }
Question 10 :
Problem Statement :
Ryuk, the Shinigami (God of death) had allowed Light Yagami, a school student, to kill as many people as he can by using a death note. But writing the names barely will allow other people to watch them. So he encrypts the names using digits, where a means 1, b means 2 and so on upto z is 26. Now if he gives numbers, there is a communication error because a number string can be decrypted by the death note in various ways and eventually killing them all. If everyone in the world has a unique name, for a given number, how many people can die?
NOTE THAT: There is every possible name in the world with the 26 letters, and capital or small letters is not a problem.
Input format:
A number stream denoting the first name’s encrypted version
Output Format:
Number of people dying by this.
Constraints:
1<=stream length<=10^8
Sample Input: 1267
Sample Output: 3
Output Specification:Two people of the name azg and lfg die.
import java.util.*; class Main { static String s; static int ans; public static void func(int i, int n) { if (i == n - 1 || i == n) { ans++; return; } if (s.charAt(i) == '1') func(i + 2, n); else if (s.charAt(i) == '2' && s.charAt(i + 1) < '7') func(i + 2, n); func(i + 1, n); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); s = sc.next(); func(0, s.length()); System.out.println(ans); } }
FAQs related to ApplicateAI
Question 1: What are the roles offered in ApplicateAI?
The roles offered in this hiring of ApplicateAI is for Software Engineer Trainee and Business Analyst Trainee, your role would initially involve extensive training for imparting the required level of skills, for effectively carrying out the official responsibilities assigned to you.
Question 2: What is ApplicateAI Recruitment Process?
The Online Selection Process consist of
- Written test
- Technical interviews
- HR discussion
Question 3:What is online assessment test in ApplicateAI?
The Online Assessment consist of
- Aptitude
- Java mcq
- JavaScript mcq
- Java coding
- JavaScript coding
Question 4: What is the Eligibility Criteria for the ApplicateAI Recruitment Process?
The Eligibility criteria is BTech in CSE&IT only 2024 batch, and having 65% and above in 10th and 12th, and CGPA 6.5 and above in B. Tech. With no active backlog(s).
Question 5: What is the Salary offered for the roles?
The Salary Package during six months training period is one twelfth of the annual package of INR 6.00 Lakhs, and later Students will be converted as full time employees (based on the performance during the six months Training / Probation Period) at the Salary Package ranging from INR 6.00 Lakhs to INR 14.10 Lakhs
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others