BYJU’s Coding Questions with Answers
Byju’s Coding Questions with Solution 2023
Byju’s Coding Questions with Answers is a part of Online Test conducted by Byju’s Exam Prep to hire Software Engineer through their recruitment Drive.
This page consists completge information about Byju’s Exam Prep Recruitment and Coding Questions asked in their Technical Assessment. You can even find eligibility criteria, salary details here. Remember that you will appear for software engineer .
About BYJU's Exam Prep
The most thorough exam preparation app in the nation, Byju’s Exam Prep, is adored by millions of applicants nationwide.
They are a fast expanding group of creative, curious, and motivated individuals who have aided over 3 billion aspirants in realising their professional goals. With an average employee age of 27, the business is young and driven, continually aiming to further the interests of aspirants.
Prime Course Trailer
Eligibility Criteria of Byju's Placement Exam
Here is the detailed Eligibility Criteria for being eligible in byjus exam prep. We have tabulated the complete information for better understanding.
Byjus Exam Prep | Eligibility Criteria |
---|---|
Course | B.Tech, M.Tech, MCA |
Branches | B.Tech (CSE, CS, CSIT, IT, ECE, EI, EN, ME, CE) , MCA & M.Tech): CSE, CS, CSIT, IT |
Batch | 2023 |
Education Qualification | 10th , 12th & Graduation, Post Graduation Percentage): 60% throughout |
Bond | No Bond |
Byju's Exam Prep Recruitment Process
Here we have explained complete placement process of Byju’s Exam Prep. Go through it carefully.
- Pre-Placement Talk
- Technical Assessment
- Interview process
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Salary for Byju's Exam Prep
Byjus | Salary Breakdown |
---|---|
Designation | Software Engineer |
CTC Offered | Rs 10 LPA |
Fixed Pay | Rs 8 Lakhs |
Joining Bonus | Rs 1 Lakh |
Performance Based | Rs 1 Lakh (Performance Based) |
Byju's Software Developer Coding Questions with Answers
Question 1 : Network Stream
Problem Statement :
A stream of n data packets arrives at a server. This server can only process packets that are exactly 2^n units long for some non-negative integer value of n (0<=n).
All packets are repackaged in order to the 1 largest possible value of 2^n units. The remaining portion of the packet is added to the next arriving packet before it is repackaged. Find the size of the largest repackaged packet in the given stream.
Example arriving Packets = [12, 25, 10, 7, 8]
The first packet has 12 units. The maximum value of 2^n that can be made has 2^n = 2^3 = 8 units because the next size up is 2^n = 2^4 = 16 (16 is greater than 12).
12 – 8 = 4 units are added to the next packet. There are 4 + 25 = 29 units to repackage, 2^n = 2^4 = 16 is the new size leaving 9 units (29-16 = 9)
Next packet is 9 + 10 = 29 unists & the maximum units(in 2^n) is 16 leaving 3 units.
3 + 7 = 10 , the max units is 8 Leaving 2 units, and so on.
The maximum repackaged size is 16 units.
Returns:
Long : the size of the largest packet that is streamed
Constraints :
1<=n<=10^5
1<=arriving Packets[i] size<=10^9
Sample case 0 :
Sample input 0:
5 → number of packets=5
13→ size of packets=[13,25,12,2,8]
25
10
2
8
Sample output 0:
16
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); int temp = 1, max = Integer.MIN_VALUE; for (int i = 0; i < n - 1; i++) { temp = 1; while (2 * temp <= arr[i]) temp = temp * 2; max = Math.max(temp, max); arr[i + 1] += arr[i] - temp; } temp = 1; while (2 * temp <= arr[n - 1]) temp = temp * 2; max = Math.max(temp, max); System.out.println(max); } }
def largeRepackagedPacket(arr): twoP = [int(2**i) for i in range(31)] x = 0 ans = 0 for i in arr: i = i + x for j in range(31): if i < twoP[j]: break x = i - twoP[j - 1] if ans <= twoP[j - 1]: ans = twoP[j - 1] return ans Packets = [] for i in range(int(input())): Packets.append(int(input())) print(largeRepackagedPacket(Packets))
Question 2 : Maximize Earnings (R->Hard)
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.
#include <bits/stdc++.h> using namespace std; class job { public: int st, ed, cost; }; int getTime(string s) { int hr = (s[0] - '0') * 10 + (s[1] - '0'); int min = (s[2] - '0') * 10 + (s[3] - '0'); return hr * 60 + min; } bool compare(job A, job B) { return A.ed < B.ed; } 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; } pair < int, int > solve(job arr[], int n) { int dp[n] = { 0 }; int numOfJobs[n] = { 0 }; dp[0] = arr[0].cost; numOfJobs[0] = 1; for (int i = 1; i < n; i++) { int cur = arr[i].cost; int num = 1; int idx = searchJob(arr, 0, i - 1, arr[i].st); if (idx != cur) { cur += dp[idx]; num += numOfJobs[idx]; } if (cur > dp[i - 1]) { dp[i] = cur; numOfJobs[i] = num; } else { dp[i] = dp[i - 1]; numOfJobs[i] = numOfJobs[i - 1]; } } return { numOfJobs[n - 1], dp[n - 1] }; } int main() { int n; cin >> n; job arr[n]; int cost; string st, ed; int total = 0; for (int i = 0; i < n; i++) { cin >> st >> ed >> cost; arr[i].st = getTime(st); arr[i].ed = getTime(ed); arr[i].cost = cost; total += cost; } sort(arr, arr + n, compare); pair < int, int > res = solve(arr, n); cout << n - res.first << endl; cout << total - res.second << endl; return 0; }
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 3 : Minimizing a string
Problem Statement :
Given a string, obtain the alphabetically smallest string possible by swapping either
adjacent ‘a’ and ‘b’ characters or adjacent ‘b’ and ‘c’ characters, any number of times.
Note: A string x is alphabetically smaller
than a string y if, for the first index i where x
and y differs, x[i] <y[i].
Example :
s=”abaacbac”
The alphabetically smallest possible string is
obtained by applying the following
operations:
‘c’at index 5 is swapped with ‘b’at index 6. So “abaacbac” becomes “abaabcac”
Then,’b’at index 2 is swapped with ‘a’at index 3. So “abaabcac” becomes “aababcac”.
Finally, ‘b’at index 3 is swapped with ‘a’at index 4 to obtain the final.
answer: “aaabbcac”.
Function Description :
Complete the function smallestString in the
editor below.
smallestString has the following
parameter(s):
string s: the given string
Returns:
string: the lexicographically smallest string obtained after swapping
Constraints :
1 <_ length of s<_ 10^5 s only contains the characters ‘a’, ‘b’, and ‘c’.
#include <bits/stdc++.h> using namespace std; //a is the smaller char b is the bigger void f(string & s, char a, char b) { int n = s.length(); bool fg = false; int st = -1; for (int i = n; i >= 0; i--) { if (s[i] == b) { if (fg) { swap(s[i], s[st]); st--; } else { continue; } } else if (s[i] == a) { if (fg) { continue; } else { fg = true; st = i; } } else { fg = false; } } } int main() { string s; cin >> s; int n = s.length(); f(s, 'b', 'c'); f(s, 'a', 'b'); cout << s << endl; return 0; }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); char arr[] = str.toCharArray(); int count = 0; for (int i = 0; i < arr.length; i++) { count = 0; for (int j = 0; j < arr.length - 1; j++) { if ((arr[j] - arr[j + 1]) == 1) { char temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; count++; } } if (count == 0) break; } System.out.println(new String(arr)); } }
s = list(input()) n = len(s) af = False fi = n + 1 for i in range(n - 1, -1, -1): if s[i] == "c": if af: s[i], s[fi] = s[fi], s[i] fi -= 1 af = False elif s[i] == "b": if af: continue else: fi = i af = True else: af = False af = False fi = n + 1 for i in range(n - 1, -1, -1): if s[i] == "b": if af: s[i], s[fi] = s[fi], s[i] fi -= 1 af = False elif s[i] == "a": if af: continue else: fi = i af = True else: af = False print(*s, sep="")
Question 4 : Minimum Occurrence (R->Medium)
Problem Statement :
Given a sting , return the character that appears the minimum number of times in the string. The string will contain only ascii characters, from the ranges (“a”-”z”,”A”-”Z”,0-9), and case matters . If there is a tie in the minimum number of times a character appears in the string return the character that appears first in the string.
Input Format:
Single line with no space denoting the input string.
Output Format:
Single character denoting the least frequent character.
Constraints:
Length of string <=10^6
Sample Input:
cdadcda
Sample Output:
c
Explanation:
C and A both are with minimum frequency. So c is the answer because it comes first with less index.
#include <bits/stdc++.h> using namespace std; unordered_map < char,int > F; int main() { string s; int m=INT_MAX; cin >> s; for(auto i:s) F[i]++; for(auto i:F) m=min(m,i.second); for(auto i:s) if(F[i]==m) { cout << i; break; } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str=sc.next(); char arr[]=str.toCharArray(); int temp[]=new int[256]; for(int i=0;i < arr.length;i++) { temp[arr[i]]++; } int min=Integer.MAX_VALUE; int index=0; for(int i=255;i >= 0;i--) { if(temp[i]==0) continue; min=Math.min(min,temp[i]); } for(int i=0;i < arr.length;i++) { if(min==temp[arr[i]]) { System.out.println(arr[i]); break; } } } }
s=input() ans=[] for i in s: ans.append(s.count(i)) print(s[ans.index(min(ans))])
Question 5 : Password Creation
Problem Statement :
A password manager wants to create new passwords using two strings given by the user, then combined to create a harder-to- guess combination. Given two strings,
interleave the characters of the strings to create a new string. Beginning with an empty string, alternately append a character from string a and from string b. If one of the strings is exhausted before the other, append the remaining letters from the other
string all at once. The result is the new password.
Example :
If a = ‘hackerrank’ and b = ‘mountain’,
The result is hmaocuknetrariannk.
Function Description :
Complete the function newPassword in the
editor below.
newPassword has the following parameter(s):
Str : string a
Str : string b
Returns:
Str: new password using two strings
Sample case 0 :
Sample input0:
abc → a=”abc”
def → b=”def”
Sample output 0:
Adbecf
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str1 = sc.next(); String str2 = sc.next(); String password = ""; int i, j; for (i = 0, j = 0; i < str1.length() && j < str2.length(); i++, j++) { password = password + str1.charAt(i) + str2.charAt(j); } if (i < str1.length()) password = password + str1.substring(i, str1.length()); if (j < str2.length()) password = password + str2.substring(j, str2.length()); System.out.println(password); } }
def newPassword(a, b): ans = "" if len(a) > len(b): m = len(b) x = a[m:] if len(a) <= len(b): m = len(a) x = b[m:] for i in range(m): ans += a[i] ans += b[i] return ans + x a = input() b = input() print(newPassword(a, b))
Byju's Coding Questions and Answers FAQ's
Question 1: What is the difficulty level of Coding in Byju's?
The coding level of Byju’s is quite difficult, you will be evaluated on the basis of in-depth knowledge.
Question 2: Do Byju's also hire for Software developer?
Yes, Byju’s do hire for Software Developer role, via a Coding exam.
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