0% found this document useful (0 votes)
56 views67 pages

Infosys Main

Uploaded by

aditya346pareek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views67 pages

Infosys Main

Uploaded by

aditya346pareek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

UBK ANNA

PLACEMENT
MATERIALS

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

About
Welcome to the ultimate resource for Infosys placement preparation! This
comprehensive guide is meticulously crafted to help you excel in every aspect of the

UF
Infosys recruitment process. Whether you're gearing up for logical reasoning, honing
your coding skills, or brushing up on technical questions, we've got you covered.

What You'll Find Inside:


Logical Reasoning: A collection of challenging puzzles and questions to sharpen your
problem-solving abilities.
Coding Challenges: Diverse coding problems designed to test and improve your
programming skills across various languages.
Technical Questions: A thorough compilation of technical questions covering essential
O
topics and concepts that Infosys focuses on.
Mock Tests: Realistic mock tests to simulate the actual exam environment, helping you
manage time and stress effectively.
KN

Why Choose This Guide?


Comprehensive Coverage: Every section is thoughtfully designed to ensure you have a
well-rounded preparation.
Expert Insights: Curated by professionals who understand the intricacies of the Infosys
recruitment process.
Practice-Oriented: Emphasis on practical questions and mock tests to build confidence
and expertise.
TE

Get Started Today!


Embark on your journey to success with our detailed and structured placement
materials. Equip yourself with the knowledge and skills needed to secure your dream
job at Infosys.

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Content
Coding Questions

Practices

UF
Interview Experiences

Mock tests
O
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Pattern

UF
No. of
Infosys Test
questions in Time Difficulty
Pattern
test

Mathematical Ability 10 35 mins Medium


O
Analytical Reasoning 15 25 mins Medium

Verbal Ability 20 20 mins High


KN

Pseudo Code 5 10 mins High

Puzzle Solving 4 10 mins Medium


TE

* In 2024 only 3 coding questions can be asked


for SP Role , so act accordingly

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Important Topic
Logical

UF
Arrangements

Puzzles

Syllogisms

Coding-Decoding
O
Number series

Cryptarithmetic

Clocks and Calendar


KN

Data Sufficiency

Most logical choice

Logical Deduction
TE

* In 2024 only 3 coding questions can be asked


for SP Role , so act accordingly

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Verbal

Reading Comprehension

Sentence Correction

UF
Sentence selection

Sentence Completion

Para Jumbles

Spotting error

Analogy
O
Fill in the Blanks

One Word Substitution

Critical Reasoning
KN
TE

* In 2024 only 3 coding questions can be asked


for SP Role , so act accordingly

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Aptitude

Percentages

Data Interpretation

UF
Permutation and Combination

Probability

Areas, Shapes, Perimeter

Speed Time and Distance / Boats and Streams

Time and Work


O
Profit and Loss | Mixtures & Allegation

Problem on Ages

Divisibility
KN

Number Decimal & Fractions

Series and Progression

LCM and HCF


TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Codings

Easy: That can be solved by applying the basic application of aptitude,


Algorithm, and Data Structures:
Easy level Question based on the following Topics:
a) Aptitude
b) Algorithm

UF
c) Stack
d) Queue
e) Tree
f) Graph
g) Hash Map
h) Linked List

Medium: That can be solved by applying the basics of the Greed algorithm.
a) Pure Greedy Algorithms.
O
b) Orthogonal Greedy Algorithms.
c) Relaxed Greedy Algorithms.

Hard: Usually a question based on Dynamic Programming.


KN

Some common examples of Dynamic Problems are :


a) Overlapping Subproblem.
b) Optimal substructure properties.
c) Knapsack problem
d) Fibonacci Numbers
e) Palindromic Subsequence
f) Longest Common Substring
TE

g) Dijkstra's algorithm

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
Input:-
Asp5w8w@k7!l23mn69

UF
Output:-
8527639

As num of special characters in the given string is even so we should


print first even digits and next odd digits in the same series present in
the string.

Input:-
O
#bn7856!@kn2n65jbnj482375
Output:-
7856523674582
KN

As count of special characters in the given string is odd so we should


first print odd digits and then even digits in the same series present in
the string
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

n=input()
a=[]
b=[]
c=[]
e=0
f=0
k=1

UF
l=0
for i in n:
if(i.isalnum()):
f=1
else: else:
e=e+1 if(len(b)>=len(a)):
for i in n: for i in a:
if(i.isdigit()): b.insert(k,i)
O
if(int(i)%2==0): k=k+2
a.append(i) else:
else: l=len(b)
b.append(i) for i in range(l):
KN

if(e%2==0): b.insert(k,a[i])
if(len(a)>=len(b)): k=k+2
for i in b: k=len(b)
a.insert(k,i) for i in range(l,len(a)):
k=k+2 b.insert(k,a[i])
else: k=k+1
l=len(a) c=b
TE

for i in range(l): m=''


a.insert(k,b[i]) for i in c:
k=k+2 m=m+str(i)
k=len(a) print(m)
for i in range(l,len(b)):
a.insert(k,b[i])
k=k+1
c=a

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
Input:- 93012630
Output:- 2,6,12,30,930,

UF
We should divide the total number into substrings and we should verify
each num is pronic num or not if pronic we should print that num

Pronic: means it is a multiple of two consecutive integers

Ex: 6->2*3 it’s a pronic


12->3*4 it’s a pronic
O
Input: 12665042
Output:- 2,6,12,42,650
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

a=int(input())
b=str(a)
n=len(b)
c=[]
k=0
l=0
for i in range(n):

UF
k=0
l=i
if(i==0):
for j in range(n):
c.append(int(b[j]))
else:
for j in range(n-i):
c.append(int(b[k:l+1]))
k=k+1
O
l=l+1
d=[]
for i in c:
if(i not in d):
KN

d.append(i)
d=sorted(d)
for i in d:
for j in range(1,150):
if(j*(j+1)==i):
print(i,end=',')
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
You are given an array of size N. You need to change this array into a

mountain. By mountain we mean, the either ends of the array should have

UF
equal elements. Then as we move towards the middle from both ends, the

next element is just one more than the previous one. So, it would have a

peak in the middle and decrease if you go towards either end, just like a

mountain.

Examples of mountains are [1, 2, 3, 2, 1] or [6, 7, 8, 8, 7, 6]. But the array


O
[1, 2, 4, 2, 1] is not a mountain because from 2 to 4 the difference is 2. The

array [1, 2, 3, 1] is also not a mountain because the elements 2 and 3 are

not equal from both ends.


KN

You need to find the minimum number of elements that should be changed

to make the array a mountain. You can make the elements negative or

zero as well.

Input Format
TE

N :: INTEGER

The first line contains an integer, N, denoting the number of elements in

array. N :: 1 -> 10^5

array :: INTEGER ARRAY

Each line i of the N subsequent lines (where 0 ≤ i < N) contains an integer

describing i-th element of array. array[i] :: 1 -> 10^6

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Input 1:

UF
4

Sample Output 1 :

Sample input 2:
O
9
1
1
1
KN

2
3
2
1
1
1
Sample Output 2:
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

#include <iostream>

using namespace std;


int mountain(int arr[], int n){
int count=0;
if(n%2==0){
int m2 = n/2;
int m1 = m2-1;

UF
if(arr[m1] == arr[m2]){
for(int i =m1-1; i>=0; i--){
if(arr[i] != (arr[i+1] -1)){
count++;
arr[i] = (arr[i+1]-1);
}
}
}
O
else if(arr[m1] != arr[m2]){
arr[m2] = arr[m1];
for(int i =m1-1; i >= 0; i--){
if(arr[i] != (arr[i+1] -1)){
KN

count++;
arr[i] = (arr[i+1]-1);
} int mid = n/2;
} for(int i = mid-1; i >= 0; i--){
if(arr[i] =! (arr[i+1]-1)){
} count++;
int j = m1-1; arr[i] = (arr[i+1]-1);
TE

for(int i =m2+1; i < n; i++){ }


if(arr[i] != arr[j]){ }
count ++; int j = mid-1;
} for(int i = mid+1;i> n;
j--; int arr[n];
} for(int i =0; i> arr[i];
return count; }
} cout << mountain(arr,n);
else{ }

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Java

import java.util.Scanner;
class Main{
public static int mountain(int[] arr, int n){
int count=0;
if(n%2==0){
int m2 = n/2;

UF
int m1 = m2-1;

if(arr[m1] == arr[m2]){
for(int i =m1-1; i>=0; i--){
if(arr[i] != (arr[i+1] -1)){ int j = mid-1;
count++; for(int i = mid+1;i < n; i++){
arr[i] = (arr[i+1]-1); if(arr[i] !=arr[j]){
} count++;
} }
O
} j--;
else if(arr[m1] != arr[m2]){ }
arr[m2] = arr[m1]; return count;
for(int i =m1-1; i>=0; i--){ }
KN

if(arr[i] != (arr[i+1] -1)){


count++; }
arr[i] = (arr[i+1]-1);
} public static void main(String[] args) {
} Scanner s = new Scanner(System.in);
int n = s.nextInt();
} int arr[] = new int[n];
TE

int j = m1-1; for(int i =0; i < n; i++){


for(int i =m2+1; i=0; i--){ arr[i]= s.nextInt();
if(arr[i] != (arr[i+1]-1)){ }
count++; System.out.println(mountain(arr,n));
arr[i] = (arr[i+1]-1); }
} }
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Input 1

989898

Sample Output 1

UF
989898

Explanation:

Xor_sum(0)=(0^989898)=989898

Sample Input 2

7
O
1

6
KN

Sample Output 2

14

Explanation

Xor_sum(4)=(4^1)+(4^6)+(4^3)=14.
TE

Sample Input 3

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
You have an interesting string S of length N. It is interesting because you

can rearrange the characters of this string in any order. You want to cut

UF
this string into some contiguous pieces such that after cutting, all the

pieces are equal to one another.

You can’t rearrange the characters in the cut pieces or join the pieces

together. You want to make the number of pieces as large as possible.

What is the maximum number of pieces you can get?


O
Note: You can observe that you may not want to cut the string at all,

therefore the number of pieces is 1. Hence, the answer always exists.

Input Format
KN

S :: STRING

The first line contains a string, S, denoting the string.

length(S) :: 1 -> 2 * 10^5

Sample Input 1:
TE

zzzzz

Sample Output 1 :

Sample input 2:

ababcc

Sample Output 2:

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample input 2:

abccdcabacda

Sample Output 2:

UF
#include<iostream>
#include<unordered_map>
#include<string>
#include<math.h>
using namespace std;
O
int ans(string s){
unordered_map map;
for(int i =0; i map[s[i]]){
val = map[s[i]];
KN

key = map[s[i]];
//we will get the smallest number.
}
}
return val;
}
TE

int main()
{
string s;
cin>>s;
cout<< ans(s);

return 0;
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Java

import java.util.*;
class Main {
public static void main(String[] args) {
String s;
Scanner sc = new Scanner(System.in);

UF
s = sc.next();
System.out.print(ans(s));
}
static int ans(String s) {
HashMap map = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
if (!map.containsKey(s.charAt(i))) {
map.put(s.charAt(i), 1);
} else {
O
map.put(s.charAt(i),map.getOrDefault(s.charAt(i), 1)+1);
}
}
int key = 100000;
KN

int val = 0;
for (int i = 0; i < s.length(); i++) {
if (key > map.get(s.charAt(i))) {
val = map.get(s.charAt(i));
key = map.get(s.charAt(i));
// we will get the smallest number.
}
TE

}
return val;
}
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
Today you decided to go to the gym. You currently have energy equal to E

units. There are N exercises in the gym. Each of these exercises drains Ai

UF
amount of energy from your body.

You feel tired if your energy reaches 0 or below. Calculate the minimum

number of exercises you have to perform such that you become tired.

Every unique exercise can only be performed at most 2 times as others

also have to use the machines.


O
If performing all the exercises does not make you feel tired, return -1.

Input Format

E :: INTEGER
KN

The first line contains an integer, E, denoting the Energy.

E :: 1 -> 10^5

N :: INTEGER

The next line contains an integer, N, denoting the number of exercises. N


TE

:: 1 -> 10^5

A :: INTEGER ARRAY

Each line i of the N subsequent lines (where 0 ≤ i < N) contains an integer

describing the amount of energy drained by i-th exercise.

A[i] :: 1 -> 10^5

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Input 1:
6
2
1
2
Sample Output 1 :
4

UF
Sample input 2:
10
2
1
2

Sample Output 2:
-1
O
Sample input 3:
2
3
1
KN

5
2
Sample Output 3:
1
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

#include <iostream>

using namespace std;

int exercise(int arr[], int test, int energy){

//check if some input == energy , if yess then return 1.


for(int i =0; i<test; i++){

UF
if(arr[i] == energy){
return 1;
}
}
int sum =0;
int ans =0;
int ans1=0;
for(int i=0; i<test; i++){ sum = sum + arr[i]; if(sum >=energy){
ans = i+1;
O
return ans;
}
}
sum =0;
KN

for(int i =0; i<test; i++){ sum = sum + arr[i]; if(2*sum >= energy){
ans1 = 2*(i+1);
return ans1;
}
}
return -1;
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

int main()
{
int energy ;
cin>>energy;
int test;
cin>>test;

int arr[test];

UF
for(int i =0; i<test; i++){ cin>> arr[i];
}

int ans = exercise(arr, test, energy);


cout << ans;

}
O
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Java

import java.util.Scanner;
public class Main {
public static int solution(int nExcercise,int[] arr,int energy){
int sum = 0;
for(int i = 0; i< nExcercise; i++) {
if(arr[i]==energy)

UF
return 1;
}
for(int i =0; i= energy){
return i+1;
}
if(2*sum >= energy){
return 2*(i+1);
}
}
O
//if sum is not equal to the energy.
return -1;
}
KN

public static void main(String[] args) {


Scanner s = new Scanner(System.in);
int energy = s.nextInt();
int nExcercise = s.nextInt();
int[] arr= new int[nExcercise];
for (int i = 0; i < nExcercise; i++)
{
TE

arr[i] = s.nextInt();
}

int ans = solution(nExcercise,arr,energy);


System.out.println(ans);
}
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
There is a battle between heroes and villains going on. You have M heroes,

all of them have the same health H. There are N villains, health of the i-th

UF
villain is Vi.

When a hero, with health H battles a villain with health Vi, one of the three

scenarios can happen:

if H > Vi: The villain is defeated, and the health of the hero is decreased by

Vi if H < Vi: The villain wins, his health is not affected, and the hero is no
O
longer able to fight. if H = Vi: Both are considered defeated, and neither

can fight.

The heroes start fighting villains one by one in the same order, first villain
KN

1 then villain 2 and so on. It might be possible that before defeating all the

villains, all the heroes are defeated. Therefore, to ensure the victory of the

heroes, you want to remove some villains from the front.

Your task is to find the minimum number of villains you need to remove
TE

from the front such that the victory of the heroes is guaranteed.

Note: If in the last battle, both the hero and villain are defeated and no

more heroes or villains remain, it would still be considered a victory since

all the villains are defeated.

Input Format

N :: INTEGER

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

The first line contains an integer, N, denoting the number of villains N


:: 1 -> 2*10^5
M :: INTEGER
The next line contains an integer, M, denoting the number of heroes
M :: 1 -> 2*10^5
H :: INTEGER
The next line contains an integer, H, denoting the health of each of
the heroes H :: 1 -> 10^9

UF
array :: INTEGER ARRAY
Each line i of the N subsequent lines (where 0 ≤ i < N) contains an
integer describing the health of each of the villains.
array[i] :: 1 -> 10^9

Sample Input 1:
Sample Output 2:
4
0
4
O
3
Sample input 3:
3
5
1
1
3
4
KN

3
1
2
Sample Output 1 :
3
0
1
3
Sample input 2:
5
Sample Output 3:
TE

3
3
3
1
2
3
1
1

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

#include <iostream>

using namespace std;


int ans(int arr[], int n, int m, int h){
int total = 0;
for(int i =0; i0; i--){
sumh= sumh+arr[i];
if(sumh >= totalhero){

UF
return i;
}
}

}
O
Implement the main function
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Java

import java.util.Scanner;
class Main{
public static int ans(int[] arr, int n, int m, int h){
int total = 0;
for(int i =0; i0; i--){

UF
sumh= sumh+arr[i];
if(sumh >= totalhero){
return i;
}
}

}
return 0;
O
}

Implement the main function


KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
Khaled has an array A of N elements. It is guaranteed that N is even. He

wants to choose at most N/2 elements from array A. It is not necessary to

UF
choose consecutive elements. Khaled is interested in XOR of all the

elements he chooses.

Here, XOR denotes the bitwise XOR operation.

For example:

If A=[2,4,6,8], then Khaled can choose the subset [2,4,8] to achieve XOR=
O
(2 XOR 4 XOR 8)=14.

Khaled wants to maximize the XOR of all the elements he chooses. Your

task is to help Khaled to find the max XOR of a subset that he can achieve
KN

by choosing at most N/2 elements?

Input format:

The first line contains an integer, N, denoting the number of elements in A.

Each line i of the N subsequent lines (where 0<=i<=N) contains an integer


TE

describing Ai.

Constraints

1<=N<=120
1<=A[i]<=10^6

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Input 1

Sample Output 1

UF
2

Explanation:

N=2, A=[1,2] Khaled can choose the subset[2]. The xor of the elements in

the subset is 2. And the number of elements in the subset is 1 which is

less than N/2.


O
Sample Input 2

1
KN

Sample Output 2
TE

Explanation:

N=4, A=[1,2,4,7] Khaled can choose the subset [7]. The xor of the elements

in the subset is 7, and the number of elements in the subset is 1 which is

less than N/2.

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Python

from itertools import combinations

def fun(arr, N):


sub = []

UF
max_xor = max(arr)
for i in range(1, N // 2):
comb = combinations(arr, i + 1)
for j in comb:
sub.append(list(j))
for a in sub:
z=0
for b in a:
z=z^b
O
if z > max_xor:
max_xor = z
return max_xor
KN

N = int(input("Enter Length : "))


arr = []
for i in range(N):
arr.append(int(input(f"Enter {i+1} Element : ")))
if N < 3:
print("Output :", max(arr))
else:
TE

print("Output :", fun(arr, N))

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CombinationXor {

public static int fun(List<Integer> arr, int N) {


List<List<Integer>> sub = new ArrayList<>();

UF
int max_xor = arr.get(0);
for (int num : arr) {
if (num > max_xor) {
max_xor = num;
}
}

for (int i = 1; i < N / 2; i++) {


combinations(arr, new ArrayList<>(), sub, i + 1, 0);
O
}

for (List<Integer> a : sub) {


int z = 0;
KN

for (int b : a) {
z = z ^ b;
}
if (z > max_xor) {
max_xor = z;
}
}
TE

return max_xor;
}

private static void combinations(List<Integer> arr, List<Integer>


temp, List<List<Integer>> sub, int len, int start) {
if (temp.size() == len) {
sub.add(new ArrayList<>(temp));
return;
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

for (int i = start; i < arr.size(); i++) {


temp.add(arr.get(i));
combinations(arr, temp, sub, len, i + 1);
temp.remove(temp.size() - 1);
}
}

public static void main(String[] args) {

UF
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Length: ");
int N = scanner.nextInt();
List<Integer> arr = new ArrayList<>();

for (int i = 0; i < N; i++) {


System.out.print("Enter " + (i + 1) + " Element: ");
arr.add(scanner.nextInt());
}
O
if (N < 3) {
int max = arr.get(0);
for (int num : arr) {
KN

if (num > max) {


max = num;
}
}
System.out.println("Output: " + max);
} else {
System.out.println("Output: " + fun(arr, N));
TE

scanner.close();
}
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
Wael is well-known for how much he loves the bitwise XOR operation,

while kaito is well known for how much he loves to sum numbers, so their

UF
friend Resli decided to make up a problem that would enjoy both of them.

Resil wrote down an array A of length N, an integer K and he defined a

new function called Xor- sum as follows

Xor-sum(x)=(x XOR A[1])+(x XOR A[2])+(x XOR A[3])+…………..+(x XOR A[N])

Can you find the integer x in the range [0,K] with the maximum Xor-sum (x)
O
value?

Print only the value.

Input format
KN

The first line contains integer N denoting the number of elements in A.

The next line contains an integer, k, denoting the maximum value of x.

Each line i of the N subsequent lines(where 0<=i<=N) contains an integer

describing Ai.
TE

Constraints

1<=N<=10^5

0<=K<=10^9

0<=A[i]<=10^9

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Output 3

46

Explanation:

Xor_sum(8)=(8^7)+(8^4) +(8^0)+(8^3)=46.

Python

def Xor_sum(x, arr):


xorSum = sum(arr)
UF
O
for i in range(1, x):
s=0
for j in arr:
s += i ^ j
KN

if s > xorSum:
xorSum = s

return xorSum

n=4
x=9
TE

arr = [7, 4, 0, 3]
print(Xor_sum(x, arr))

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Java

public class Main {

public static int xorSum(int x, int[] arr) {


int xorSum = 0;

UF
for (int num : arr) {
xorSum += num;
}

for (int i = 1; i < x; i++) {


int s = 0;
for (int num : arr) {
s += i ^ num;
}
O
if (s > xorSum) {
xorSum = s;
}
}
KN

return xorSum;
}

public static void main(String[] args) {


int n = 4;
int x = 9;
TE

int[] arr = {7, 4, 0, 3};


System.out.println(xorSum(x, arr));
}
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
One of the first lessons IT students learn is the representation of natural

numbers in the binary number system (base 2) This system uses only two

UF
digits, 0 and 1. In everyday life we use for convenience the decimal

system (base 10) which uses ten digits, from 0 to 9. In general, we could

use any numbering system.

Computer scientists often use systems based on 8 or 16. The numbering

system based on K uses K digits with a value from 0 to K-1. Suppose a

natural number M is given, written in the decimal system To convert it to


O
the corresponding writing in the system based on K, we successively

divide M by K until we reach a quotient that is less than K


KN

The representation of M in the system based on K is formed by the final

quotient (as first digit) and is followed by the remainder of the previous

divisions For example : If M=122 and K=8, 122 in base 10= 172 in base 8

This means that the number

In decimal system = 172 in octal system.


TE

172 in base 8 = 1*8^2 + 7*8 + 2 = 122

You made the following observation in applying the above rule of

converting natural numbers to another numbering system

In some cases in the new representation all the digits of the number are

the same. For example 63 in base

10= 333 in base 4

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Given a number M in its decimal representation, your task is find the

minimum base B such that in the representation of M at base B all digits

are the same.

Input Format

The first line contains an integer, M, denoting the number given

UF
Constraints

1 <= M = 10^12

Sample Input 1 :

41

Sample Output 1 :
O
40

Explanation :
KN

Here 41 in base 40. will be 11 so it has all digits the same, and there is no

smaller base satisfying the requirements

Sample Input 2 :

34430

Sample Output 2 :
TE

312

Explanation :

Here 34430 in base 312 will have all digits the same and there is no

smaller base satisfying the requirements

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Python

def convertBase(m, base):


rem = m % base
m = m // base
while m >= base and (m % base == rem):

UF
m = m // base
if m == rem:
return True
return False

m = int(input())
base = 2
while not convertBase(m, base):
base = base + 1
O
print(base)
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Java

import java.util.Scanner;

public class BaseConversion {

UF
public static boolean convertBase(int m, int base) {
int rem = m % base;
m = m / base;
while (m >= base && (m % base == rem)) {
m = m / base;
}
return m == rem;
}
O
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int m = scanner.nextInt();
KN

int base = 2;
while (!convertBase(m, base)) {
base++;
}
System.out.println(base);
scanner.close();
}
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
Andy wants to go on a vacation to de-stress himself. Therefore he decides

to take a trip to an island. It is given that he has as many consecutive

UF
days as possible to rest, but he can only make one trip to the island.

Suppose that the days are numbered from 1 to N. Andy has M obligations

in his schedule, which he has already undertaken and which correspond to

some specific days. This means that ith obligation is scheduled for day Di.

Andy is willing to cancel at most k of his obligations in order to take more

holidays.
O
Your task is to find out the maximum days of vacation Andy can take by

canceling at most K of his obligations.


KN

Input Format

The first line contains an integer N, denoting the total number of days

The next line contains an integer M denoting the total number of

obligations.

The next line contains an integer K denoting the largest number of


TE

obligations he could cancel

Each line i of the M subsequent lines (where 0<=i<=M) contains an integer

describing Di.

Constraint

1<=N<=10^6 1<=K<=2*10^6
1<=M<=2*10^6 1<=D[i]<=10^6

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Input 1:

10

UF
9

Sample Output 1 :

5
O
Explanation:

Here he could cancel his 3rd and 4th obligation which makes vacation
KN

length 5.

Sample input 2:
7
2
0
3
TE

4
Sample Output 2:
3
Explanation:
Here he could not cancel any obligation since K=0, so the vacation length
is 3.

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Python

n = int(input())
m = int(input())
k = int(input())
arr = [0] * n

UF
for i in range(m):
arr[i] = int(input())
ans = 0
arr.sort()
if k > 0:
for i in range(k + 1, m + 3, 1):
ans = max(ans, arr[i] - arr[i - k - 1] - 1)
else:
j=0
O
while arr[j] == 0:
j=j+1
count = 0
for i in range(1, n + 1, 1):
KN

count += 1
if j < n and (i == arr[j]):
count = 0
j += 1
ans = max(count, ans)
print(ans)
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Java

import java.util.Arrays;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

UF
Scanner scanner = new Scanner(System.in);

int n = scanner.nextInt();
int m = scanner.nextInt();
int k = scanner.nextInt();

int[] arr = new int[n];

for (int i = 0; i < n; i++) {


O
arr[i] = 0;
}

for (int i = 0; i < m; i++) {


KN

arr[i] = scanner.nextInt();
}

int ans = 0;

Arrays.sort(arr);
TE

if (k > 0) {
for (int i = k + 1; i < m + 3; i++) {
ans = Math.max(ans, arr[i] - arr[i - k - 1] - 1);
}
} else {
int j = 0;
while (j < n && arr[j] == 0) {
j++;
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

int count = 0;
for (int i = 1; i <= n; i++) {
count++;
if (j < n && (i == arr[j])) {
count = 0;
j++;

UF
}
ans = Math.max(count, ans);
}
}

System.out.println(ans);
scanner.close();
}
}
O
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
You need to build a road in a rugged terrain. You know the sea level of

each segment of the rugged terrain, i.e., the i-th segment is Li meters from

UF
sea level.

You need to transform the terrain into a strictly downward sloping terrain

for the road, i.e., for each i-th segment where 2 <= i <= N, resultant Li-1 >

Li. To do so, you employ a powerful digging team to help you dig and

reduce the sea level of the segments. On day D, the team can reduce the

sea level for each segment that you scheduled that day by 2D-1 meters
O
each.

You are allowed to assign the team to dig on multiple segments and/or dig
KN

on the same segments for multiple days.

Your task is to find the minimum number of days needed to transform the

terrain as per your requirements.

Input Format
TE

N :: INTEGER

The first line contains an integer, N, denoting the number of elements in L.

N :: 1 -> 10^5

L :: INTEGER ARRAY

Each line i of the N subsequent lines (where 0 < i ≤ N) contains an integer

describing Li, the sea level of the i-th segment. L[i] :: -10^9 -> 10^9

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Input 1:
2
3
3
Sample Output 1 :
1
Sample input 2:

UF
2
5
-3
Sample Output 2:
0
O
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Python

import math

def main():
# Read input

UF
n = int(input())
a = [int(input()) for _ in range(n)]

max_dig = 0
for i in range(n - 1):
if a[i] <= a[i + 1]:
max_dig = max(max_dig, (a[i + 1] - a[i] + 1))
a[i + 1] = a[i] - 1
O
ans = math.ceil(math.sqrt(max_dig))
print(ans)

if __name__ == "__main__":
KN

main()
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Java

import java.util.Scanner;
import java.util.Arrays;

public class Main {

UF
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int n = scanner.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.nextInt();
}
O
long max_dig = 0;
for (int i = 0; i < n - 1; i++) {
if (a[i] <= a[i + 1]) {
KN

max_dig = Math.max(max_dig, (a[i + 1] - a[i] + 1));


a[i + 1] = a[i] - 1;
}
}

int ans = (int) Math.ceil(Math.sqrt(max_dig));


System.out.println(ans);
TE

scanner.close();
}
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
You are given an array of size N. You need to change this array into a

mountain. By mountain we mean, the either ends of the array should have

UF
equal elements. Then as we move towards the middle from both ends, the

next element is just one more than the previous one. So, it would have a

peak in the middle and decrease if you go towards either end, just like a

mountain.

Examples of mountains are [1, 2, 3, 2, 1] or [6, 7, 8, 8, 7, 6]. But the array

[1, 2, 4, 2, 1] is not a mountain because from 2 to 4 the difference is 2. The


O
array [1, 2, 3, 1] is also not a mountain because the elements 2 and 3 are

not equal from both ends.


KN

You need to find the minimum number of elements that should be changed

to make the array a mountain. You can make the elements negative or

zero as well.

Input Format

N :: INTEGER
TE

The first line contains an integer, N, denoting the number of elements in

array. N :: 1 -> 10^5 array :: INTEGER ARRAY

Each line i of the N subsequent lines (where 0 ≤ i < N) contains an integer

describing i-th element of array. array[i] :: 1 -> 10^6

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Input 1:

UF
4

Sample Output 1 :

Sample input 2:

9
O
1

1
KN

1
TE

Sample Output 2:

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Python

def mountain(arr, n):


count = 0
if n % 2 == 0:
m2 = n // 2
m1 = m2 - 1
if arr[m1] == arr[m2]:

UF
for i in range(m1 - 1, -1, -1):
if arr[i] != (arr[i + 1] - 1):
count += 1
arr[i] = (arr[i + 1] - 1)
else:
arr[m2] = arr[m1]
for i in range(m1 - 1, -1, -1):
if arr[i] != (arr[i + 1] - 1):
count += 1
O
arr[i] = (arr[i + 1] - 1)

j = m1 - 1
for i in range(m2 + 1, n):
KN

if arr[i] != arr[j]:
count += 1
j -= 1
else:
mid = n // 2
for i in range(mid - 1, -1, -1):
if arr[i] != (arr[i + 1] - 1):
TE

count += 1
arr[i] = (arr[i + 1] - 1)

j = mid - 1
for i in range(mid + 1, n):
if arr[i] != arr[j]:
count += 1
j -= 1

return count

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

def main():
n = int(input("Enter the number of elements: "))
arr = [int(input()) for _ in range(n)]
print(mountain(arr, n))

if __name__ == "__main__":

UF
main()
O
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

import java.util.Scanner;

public class Main {

public static int mountain(int[] arr, int n) {


int count = 0;

if (n % 2 == 0) {
int m2 = n / 2;
int m1 = m2 - 1;

UF
if (arr[m1] == arr[m2]) {
for (int i = m1 - 1; i >= 0; i--) {
if (arr[i] != (arr[i + 1] - 1)) {
count++;
arr[i] = arr[i + 1] - 1;
}
}
} else {
O
arr[m2] = arr[m1];
for (int i = m1 - 1; i >= 0; i--) {
if (arr[i] != (arr[i + 1] - 1)) {
count++;
KN

arr[i] = arr[i + 1] - 1;
}
}
}

int j = m1 - 1;
for (int i = m2 + 1; i < n; i++) {
if (arr[i] != arr[j]) {
TE

count++;
}
j--;
}
} else {
int mid = n / 2;
for (int i = mid - 1; i >= 0; i--) {
if (arr[i] != (arr[i + 1] - 1)) {
count++;
arr[i] = arr[i + 1] - 1;
}
}
teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

int j = mid - 1;
for (int i = mid + 1; i < n; i++) {
if (arr[i] != arr[j]) {
count++;
}
j--;
}
}

UF
return count;
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of elements: ");


int n = scanner.nextInt();
O
int[] arr = new int[n];
System.out.println("Enter the elements:");
for (int i = 0; i < n; i++) {
KN

arr[i] = scanner.nextInt();
}

int result = mountain(arr, n);


System.out.println("Number of changes needed: " + result);

scanner.close();
TE

}
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Coding Questions
You have been given a string S of length N. The given string is a binary

string which consists of only 0’s and ‘1’s. Ugliness of a string is defined as

UF
the decimal number that this binary string represents.

Example:

“101” represents 5.

“0000” represents 0.

“01010” represents 10.

There are two types of operations that can be performed on the given
O
string.

Swap any two characters by paying a cost of A coins. Flip any character
KN

by paying a cost of B coins flipping a character means converting a ‘1’to a

‘0’or converting a ‘0’ to a ‘1’.

Initially, you have been given coins equal to the value defined in CASH.

Your task is to minimize the ugliness of the string by performing the above

mentioned operations on it. Since the answer can be very large, return the
TE

answer modulo 10^9+7.

Note:

You can perform an operation only if you have enough number of coins to

perform it.

After every operation the number of coins get deducted by the cost for

that operation.

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Input Format

The first line contains an integer, N, denoting the number of character in

the string

The next line contains a string, S, denoting the the binary string

The next line contains an integer, CASH, denoting the total number of

UF
coins present initially

Next will contains an integer, A, denoting the cost to swap two

characters.

Then the next line contains an integer, B, denoting the cost to flip a

character.

Constraints
O
1 <= N <= 10^5

1< len(S)<= 10^5


KN

1<=CASH <=10^5

1<=A<=10^5

1<=B<=10^5

Sample Input 1 :
4
TE

1111
7
1
2

Sample Output 1 :
1
Explanation:
3 flips can be used to create “0001” which represents 1.

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Sample Input 2:

111011

UF
3

Sample Output 2:

Explanation:

First swap 0 with the most significant 1, then use flip twice first on index

one and then on index two “111011”=>”0111111″=>”001111″=>”000111″


O
the value represented is 7.

Sample Input 3:
KN

111011

2
TE

Sample Output 3:

Explanation:

Flip the 3 most significant characters to get “000011” : the value

represented by this string is 3.N

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

import java.util.Scanner;

public class Main {

static String s;
static int n, cash, a, b;

UF
static void swapf() {
int i = 0;
while (i < s.length() && s.charAt(i) != '1') {
i++;
}

int j = s.length() - 1;
while (j > i && cash >= a) {
O
if (s.charAt(j) == '0') {
if (s.charAt(i) == '0') {
i++;
} else {
KN

StringBuilder sb = new StringBuilder(s);


sb.setCharAt(i, '0');
sb.setCharAt(j, '1');
s = sb.toString();
cash -= a;
i++;
j--;
TE

}
} else {
j--;
}
}
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

static void flipf() {


int i = 0;
while (i < s.length() && cash >= b) {
if (s.charAt(i) == '1') {
StringBuilder sb = new StringBuilder(s);
sb.setCharAt(i, '0');

UF
s = sb.toString();
cash -= b;
}
i++;
}
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
O
n = scanner.nextInt();
s = scanner.next();
cash = scanner.nextInt();
a = scanner.nextInt();
KN

b = scanner.nextInt();

if (a < b) {
swapf();
flipf();
} else {
flipf();
TE

swapf();
}

long result = Long.parseLong(s, 2);


System.out.println(result);

scanner.close();
}
}

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Python

def flipf():
global s, cash, b
i=0
s = list(s)

UF
while i < len(s) and cash >= b:
if s[i] == '1':
s[i] = '0'
cash -= b
i += 1
s = ''.join(s)

def swapf():
global s, cash, a
O
i=0
while i < len(s) and s[i] != '1':
i += 1
KN

j = len(s) - 1
while j > i and cash >= a:
if s[j] == '0':
if s[i] == '0':
i += 1
else:
s = list(s)
TE

s[i], s[j] = s[j], s[i]


s = ''.join(s)
cash -= a
j -= 1
else:
j -= 1

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

def main():
global s, cash, a, b
n = int(input("Enter the number of elements: "))
s = input("Enter the binary string: ")
cash = int(input("Enter the cash amount: "))
a = int(input("Enter the cost of swap: "))
b = int(input("Enter the cost of flip: "))

UF
if a < b:
swapf()
flipf()
else:
flipf()
swapf()
O
result = int(s, 2)
print(result)

if __name__ == "__main__":
KN

s = ""
cash = 0
a=0
b=0
main()
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Practice

UF
Quants, Verbal & Logical O
KN

Coding Questions
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

Interview Experience

UF
O
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

MOCK TEST

UF
O
KN
TE

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf
UBK ANNA

AFFORDABLE PLACEMENT MATERIALS

UF
O
69 X 6 = 414/- PAY ONLY
KN

249/-

TO GET DM - 👆🏽 👇🏽
TE

INSTAGRAM.COM/TEKNO.UF

teknouf
youtube.com/@teknouf
instagram.com/tekno.uf

You might also like