Red Hat Coding Questions with Answers
Red Hat Coding Questions With Solutions
Red Hat Coding Questions and Answers page will help you to prepare yourself to appear for recruitment drives for the designation of Software Engineer and Software Engineer Intern in Red Hat.
The page is mainly focused on the Insights on Steps of recruitment process of the company and what are the preferences of the company’s recruitment team to hire the candidate.
About Red Hat
Red Hat is a software company known for its enterprise open-source solutions. Founded in 1993, Red Hat has become a prominent player in the world of Linux-based operating systems and has expanded its offerings to encompass a wide range of enterprise software and services. In 2019, Red Hat was acquired by IBM, further bolstering its capabilities and market reach.
They mainly work on – open-source projects, Red Hat Enterprise Linux (RHEL), OpenShift, and Red Hat JBoss Enterprise Application Platform (JBoss EAP), a Java-based application server for building and deploying enterprise applications.
About Red Hat Hiring Process
Here we have mentioned everything regarding the Red Hat Recruitment Process. Going through each process is mandatory and every round is an elimination round.
- Round 1: Online Coding Test
- Round 2: Technical Interview – 1
- Round 3: Technical Interview – 2
- Round 4: HR Interview
Here we have mentioned some significant details of Red Hat hiring process in following tabular form:
Red Hat | Related Information |
---|---|
Position : |
|
Course : |
|
Eligibility Criteria / Academic Qualification Required : |
|
Cost to Company (CTC) | ₹ 12 – 13 L.P.A |
Selection Process : |
|
Joining Location : | Remote |
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Sample Red Hat Coding Questions with Solutions
Question : 1
Problem Statement – Abhijeet is one of those students who tries to get his own money by part time jobs in various places to fill up the expenses for buying books. He is not placed in one place, so what he does, he tries to allocate how much the book he needs will cost, and then work to earn that much money only. He works and then buys the book respectively. Sometimes he gets more money than he needs so the money is saved for the next book. Sometimes he doesn’t. In that time, if he has stored money from previous books, he can afford it, otherwise he needs money from his parents.
Now His parents go to work and he can’t contact them amid a day. You are his friend, and you have to find how much money minimum he can borrow from his parents so that he can buy all the books.
He can Buy the book in any order.
Function Description:
Complete the function with the following parameters:
Name | Type | Description |
N | Integer | How many Books he has to buy that day. |
EarnArray[ ] | Integer array | Array of his earnings for the ith book |
CostArray[ ] | Integer array | Array of the actual cost of the ith book. |
Constraints:
- 1 <= N <= 10^3
- 1 <= EarnArray[i] <= 10^3
- 1 <= CostArray[i] <= 10^3
Input Format:
- First line contains N.
- Second N lines contain The ith earning for the ith book.
- After that N lines contain The cost of the ith book.
Output Format: The minimum money he needs to cover the total expense.
Sample Input 1:
3
[3 4 2]
[5 3 4]
Sample Output 1:
3
Explanation:
At first he buys the 2nd book, which costs 3 rupees, so he saves 1 rupee. Then he buys the 1st book, that takes 2 rupees more. So he spends his stored 1 rupee and hence he needs 1 rupee more. Then he buys the last book.
#include<bits/stdc++.h> using namespace std; int main() { int n, ans = 0, sum = 0; cin >> n; vector< int > arr1(n), arr2(n); for (int i = 0; i < n; i++) { cin >> arr2[i]; } for (int i = 0; i < n; i++) { cin >> arr1[i]; } for (int i = 0; i < n; i++) { arr2[i] -= arr1[i]; } sort(arr2.begin(), arr2.end(), greater< int >()); for (int i = 0; i < n; i++) { sum += arr2[i]; if (sum < 0) { ans += abs(sum); sum = 0; } } cout << ans << endl; return 0; }
n = int(input()) ans = 0 su = 0 arr2 = list(map(int, input().split())) arr1 = list(map(int, input().split())) for i in range(n): arr2[i] -= arr1[i] arr2.sort(reverse=True) for i in range(n): su += arr2[i] if su < 0: ans += abs(su) su = 0 print(ans)
import java.util.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner (System.in); int n=sc.nextInt(); int arr1[]= new int[n]; int arr2[]= new int[n]; for(int i=0; i<n; i++) arr2[i]=sc.nextInt(); for(int i=0; i<n; i++) arr1[i]=sc.nextInt(); for(int i=0; i<n; i++) arr2[i] -= arr1[i]; Arrays.sort(arr2); int sum=0, ans=0; for(int i=n-1; i>=0; i--) { sum+=arr2[i]; if(sum<0) { sum = -sum; ans= ans +sum ; sum=0; } } System.out.println(ans); } }
Question : 2
Problem Description
Question:- Krishna loves candies a lot, so whenever he gets them, he stores them so that he can eat them later whenever he wants to.
He has recently received N boxes of candies each containing Ci candies where Ci represents the total number of candies in the ith box. Krishna wants to store them in a single box. The only constraint is that he can choose any two boxes and store their joint contents in an empty box only. Assume that there are an infinite number of empty boxes available.
At a time he can pick up any two boxes for transferring and if both the boxes contain X and Y number of candies respectively, then it takes him exactly X+Y seconds of time. As he is too eager to collect all of them he has approached you to tell him the minimum time in which all the candies can be collected.
Input Format:
- The first line of input is the number of test case T
- Each test case is comprised of two inputs
- The first input of a test case is the number of boxes N
- The second input is N integers delimited by whitespace denoting the number of candies in each box
Output Format: Print minimum time required, in seconds, for each of the test cases. Print each output on a new line.
Constraints:
- 1 < T < 10
- 1 < N< 10000
- 1 < [Candies in each box] < 100009
S. No. | Input | Output |
---|---|---|
1 | 1 4 1 2 3 4 | 19 |
2 | 1 5 1 2 3 4 5 | 34 |
Explanation for sample input-output 1:
4 boxes, each containing 1, 2, 3 and 4 candies respectively.Adding 1 + 2 in a new box takes 3 seconds.Adding 3 + 3 in a new box takes 6 seconds.Adding 4 + 6 in a new box takes 10 seconds.Hence total time taken is 19 seconds. There could be other combinations also, but overall time does not go below 19 seconds.
Explanation for sample input-output 2:
5 boxes, each containing 1, 2, 3, 4 and 5 candies respectively.Adding 1 + 2 in a new box takes 3 seconds.Adding 3 + 3 in a new box takes 6 seconds.Adding 4 + 6 in a new box takes 10 seconds.Adding 5 + 10 in a new box takes 15 seconds.Hence total time taken is 34 seconds. There could be other combinations also, but overall time does not go below 33 seconds.
#include <stdio.h> int main() { int i,j; int num_box=0,k=0,sum=0,times=0,tst_case,temp=0; long c[10000],s[10000]; printf("Enter the number of test case:"); scanf("%d",&tst_case); printf("Enter the number of boxes:"); for(int l=0;l<tst_case;l++) { scanf("%d",&num_box); } printf("Enter the number of candies in each box:"); for(i=0;i<num_box;i++) { scanf("%ld",&c[i]); } for(i=0;i<num_box;i++) { for(j=i+1;j<num_box;j++) { if(c[i]>c[j]) { temp=c[i]; c[i]=c[j]; c[j]=temp; } } } sum=0; k=0; for(i=0;i<num_box;i++) { sum=sum+c[i]; s[k]=sum; k++; } times=0; printf("Minimum time requried:"); for(i=1;i<k;i++) times=times+s[i]; printf("%d\n",times); return 0; }
Output 1 4 1 2 3 4 19
#include<bits/stdc++.h> using namespace std; int main() { int i,j; int num_box=0,k=0,sum=0,times=0,tst_case,temp=0; long c[10000],s[10000]; cout<<("Enter the number of test case:"); cin>>tst_case; cout<<("Enter the number of boxes:"); for(int l=0;l<tst_case;l++) { cin>>num_box; } cout<<("Enter the number of candies in each box:"); for(i=0;i<num_box;i++) { cin>>c[i]; } for(i=0;i<num_box;i++) { for(j=i+1;j<num_box;j++) { if(c[i]>c[j]) { temp=c[i]; c[i]=c[j]; c[j]=temp; } } } sum=0; k=0; for(i=0;i<num_box;i++) { sum=sum+c[i]; s[k]=sum; k++; } times=0; cout<<("Minimum time requried:"); for(i=1;i<k;i++) times=times+s[i]; cout<<times; return 0; }
Output 1 4 1 2 3 4 19
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, i, k = 0, sum = 0, s1 = 0, t, temp = 0, j; long c[] = new long[1000009]; long s[] = new long[100009]; t = sc.nextInt(); for (int l = 0; l < t; l++) { n = sc.nextInt(); for (i = 0; i < n; i++) c[i] = sc.nextLong(); for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (c[i] > c[j]) { temp = (int) c[i]; c[i] = c[j]; c[j] = temp; } } } sum = 0; k = 0; for (i = 0; i < n; i++) { sum = (int) (sum + c[i]); s[k] = sum; k++; } s1 = 0; for (i = 1; i < k; i++) s1 = (int) (s1 + s[i]); System.out.println(s1); } } }
Output 1 4 1 2 3 4 19
T = int(input()) arr1 = [] for _ in range(T): N = int(input()) arr = list(map(int, input().split())) arr.sort() count = arr[0] for i in range(1, len(arr)): count += arr[i] arr1.append(count) print(sum(arr1))
Output 1 4 1 2 3 4 19
Question : 3
Rahul has an array a, consisting of n integers a1, a2, …, an. The boy cannot sit and do nothing, he decided to study an array. Rahul took a piece of paper and wrote out m integers l1, l2, …, lm (1 ≤ li ≤ n). For each number li he wants to know how many distinct numbers are staying on the positions li, li + 1, …, n. Formally, he want to find the number of distinct numbers among ali, ali + 1, …, an.?
Rahul wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each li.
Input
- The first line contains two integers n and m (1 ≤ n, m ≤ 105). The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ 105) — the array elements.
- Next m lines contain integers l1, l2, …, lm. The i-th line contains integer li (1 ≤ li ≤ n).
Output
- Print m lines — on the i-th line print the answer to the number li.
Examples
- Input
10 10
1 2 3 4 1 2 3 4 100000 99999
1
2
3
4
5
6
7
8
9
10 - Output
6
6
6
6
6
5
4
3
2
1
n,m=map(int,input().split()) ar=list(map(int,input().split())) a=set() l=[0]*n for i in range(n-1,-1,-1): a.add(ar[i]) l[i]=len(a) #print(l) for i in range(m): lx=int(input()) print(l[lx-1])
#include<bits/stdc++.h> using namespace std; int main () { int n, m; cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; set < int >st; int check[n] = { 0 }; for (int i = n - 1; i >= 0; i--) { st.insert (a[i]); check[i] = st.size (); } for (int i = 0; i < m; i++) cout << check[b[i] - 1] << endl; return 0; }
import java.util.*; class Main { public static void main (String[]args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt (); int m = sc.nextInt (); int a[] = new int[n]; int l[] = new int[m]; for (int i = 0; i < n; i++) a[i] = sc.nextInt (); for (int j = 0; j < m; j++) l[j] = sc.nextInt (); int dp[] = new int[n]; HashSet < Integer > s = new HashSet < Integer > (); for (int i = n - 1; i >= 0; i--) { s.add (a[i]); dp[i] = s.size (); } for (int j = 0; j < m; j++) System.out.println (dp[l[j] - 1]); } }
Question : 4
You just received another bill which you cannot pay because you lack the money.
Unfortunately, this is not the first time to happen, and now you decide to investigate the cause of your constant monetary shortness. The reason is quite obvious: the lion’s share of your money routinely disappears at the entrance of party localities.
You make up your mind to solve the problem where it arises, namely at the parties themselves. You introduce a limit for your party budget and try to have the most possible fun with regard to this limit.
You inquire beforehand about the entrance fee to each party and estimate how much fun you might have there. The list is readily compiled, but how do you actually pick the parties that give you the most fun and do not exceed your budget?
Write a program which finds this optimal set of parties that offer the most fun. Keep in mind that your budget need not necessarily be reached exactly. Achieve the highest possible fun level, and do not spend more money than is absolutely necessary.
Input
- The first line of the input specifies your party budget and the number n of parties.
- The following n lines contain two numbers each. The first number indicates the entrance fee of each party. Parties cost between 5 and 25 francs. The second number indicates the amount of fun of each party, given as an integer number ranging from 0 to 10.
- The budget will not exceed 500 and there will be at most 100 parties. All numbers are separated by a single space.
- There are many test cases. Input ends with 0 0.
Output
- For each test case your program must output the sum of the entrance fees and the sum of all fun values of an optimal solution. Both numbers must be separated by a single space.
Example
- Sample input:
50 10
12 3
5 8
16 9
16 6
10 2
21 9
18 4
12 4
17 8
18 9
50 10
13 8
19 10
16 8
12 9
10 2
12 8
13 5
15 5
11 7
16 2
0 0
- Sample output:
50 29
48 32
def knapSack(W, wt, val, n): K = [[0 for x in range(W + 1)] for x in range(n + 1)] for i in range(n + 1): for w in range(W + 1): if i == 0 or w == 0: K[i][w] = 0 elif wt[i-1] <= w: K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]) else: K[i][w] = K[i-1][w] res = K[n][W] res1=res x=0 w = W for i in range(W+1): if(K[n][i]==res): x=i break print(x , res1) b,n=map(int,input().split()) fun=[] cost=[] for i in range(n): x,y=map(int,input().split()) fun.append(y) cost.append(x) (knapSack(b,cost,fun,n))
import java.util.*; class Main { public static void main (String[]args) { Scanner sc = new Scanner (System.in); while (true) { int budget = sc.nextInt (); int n = sc.nextInt (); if (budget == 0 && n == 0) break; int cost[] = new int[n + 1]; int fun[] = new int[n + 1]; int arr[][] = new int[n + 1][budget + 1]; for (int i = 0; i < n; i++) { cost[i] = sc.nextInt (); fun[i] = sc.nextInt (); } for (int i = 0; i <= n; i++) for (int j = 0; j <= budget; j++) arr[i][j] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= budget; j++) if (cost[i - 1] <= j) arr[i][j] =Math.max (fun[i - 1] + arr[i - 1][j - cost[i - 1]],arr[i - 1][j]); else arr[i][j] = arr[i - 1][j]; } int c = 0; for (int i = 0; i <= budget; i++) { if (arr[n][i] == arr[n][budget]) { c = i; break; } } System.out.println (c + " " + arr[n][budget]); } } }
#include<bits/stdc++.h> using namespace std; int main() { int w, n; x: cin >> w >> n; if (w == 0 and n == 0) goto r; else { int ct[n], val[n]; for (int i = 0; i < n; i++) { cin >> ct[i] >> val[i]; } int t[n + 1][w + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) t[i][j] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (ct[i - 1] <= j) t[i][j] = max(val[i - 1] + t[i - 1][j - ct[i - 1]], t[i - 1][j]); else t[i][j] = t[i - 1][j]; } } int cost = 0; for (int i = 0; i <= w; i++) { if (t[n][i] == t[n][w]) { cost = i; break; } } cout << cost << " " << t[n][w] << endl; goto x; } r: return 0; }
Question : 5
Ajay has a flight to catch in an hour. So he has to reach the airport as fast at possible. He hires a taxi and promises the taxi driver that if he reaches the airport within k minutes he would pay the taxi driver double the amount.
The city description is as follows –
The taxi is at point 0,0 & airport is at (n-1,m-1) in a 2 – D grid of n rows and m columns. The grid has some blocked (represented as’#’) and some unblocked (represented as’.’) cells.
The starting position of the taxi is in the top – left corner of the grid. It is guaranteed that the starting position & ending positions are not blocked. Each cell of the grid is connected with its right ,left,top,bottom cells (if those cells exist ). It takes 1 second for a taxi to move from a cell to its adjacent cell.
If the taxi can reach the bottom-right (airport) corner of the grid within k seconds, return the string ‘Yes’. Otherwise , return the string ‘No’.
Example
rows =3
grid =[‘..##’,’#.##’,’#…’]
maxTime =5
..##
#.##
#…
It will take the taxi 5 seconds to reach the bottom right corner. As long as k>_5,return
‘Yes’.
Returns:
String;the final string; either ‘yes’ or ‘ No’
Constraints
- 1<_rows<_500
- 0<_maxTime<_10^6
Input Format For Custom Testing
- The first line contains an integer,rows that denotes the number of rows of the 2-D grid
- In each of the next rows lines, the i^th line contains a string denoting the configuration of the i^th row of the grid.
- The last line contains an integer, maxTime ,that represents the maximum time in seconds the taxi has to reach the bottom right cell.
Example
- Sample Input 0
2 -> size of grid[] rows =2
.. -> grid = [‘..’,’..’]
..
3 -> maxTime = 3
- Sample Output 0
Yes
Explanation
The grid has 2 rows and 2 columns and the time within which the taxi needs to reach the bottom-right cell in 3 seconds. Starting from the top-left cell, the taxi can either move to the top-right unblocked
#python Program from collections import deque def shortestPath(grid, k): #print(grid) n, m = len(grid), len(grid[0]) queue = deque([(0, 0,0)]) visited = {(0, 0)} while queue: x, y,dist = queue.popleft() if (x, y) == (n-1, m-1): return dist else: for dx, dy in ((-1, 0), (+1, 0), (0, -1), (0, +1)): nx, ny = x + dx, y + dy key = (nx, ny) if not (0 <= nx < n and 0 <= ny < m) or key in visited: continue if grid[nx][ny] == '.': visited.add(key) queue.append((nx, ny,dist + 1)) return -1 n=int(input()) ar=[] for i in range(n): s=list(input()) ar.append(s) k=int(input()) #a=(shortestPath(ar,k)) print(a) if(a<=k): print('YES') else: print('NO')
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char matrix[][] = new char[n][n];for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) matrix[i][j] = sc.next().charAt(0); int dp[][] = new int[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[i][j] = Integer.MAX_VALUE; long maxTime = sc.nextInt(); dp[0][0] = 0; for (int i = 1; i < n; i++) { if (matrix[0][i] == ‘#’) break; dp[0][i] = dp[0][i – 1] + 1; } for (int i = 1; i < n; i++) { if (matrix[i][0] == ‘#’) break; dp[i][0] = dp[i – 1][0] + 1; } for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { if (matrix[i][j] == ‘#’) continue; dp[i][j] = Math.min(dp[i – 1][j], dp[i][j – 1]) + 1; } } if (dp[n – 1][n – 1] < maxTime) System.out.println(“Yes”); else System.out.println(“No”); } }
FAQs on Red Hat Coding Questions
Question 1: How many rounds are there in Red Hat Hiring Process?
There are in total three rounds in the Red Hat Hiring Process which includes:-
- Coding Assessments
- Technical Interview
- HR Interview
Question 2: Is Coding questions asked in Red Hat Recruitment Process?
Yes, Coding Questions are included in Online Assessment and Technical Interview of Red Hat.
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
Login/Signup to comment