Reliance Jio Coding Questions and Answers
Reliance Jio Coding Questions with Answers 2023
You’re all probably curious about the number and kind of coding problems that will be included in the Reliance Jio exam. No need to worry, prepsters We will cover every aspect of the Reliance Jio Coding Questions and Answers on this page.
Reliance Jio’s Coding Pattern has been somewhat modified this year. Pattern-based practice problems for the Reliance Jio Coding Round are accessible on this Page.
Lets Prepare Better Faster
Reliance Jio Coding Pattern In Detail
| Company Name | Reliance Jio |
|---|---|
| Total Rounds | 2 |
| Written Test |
|
| Interview |
|
| Total Question |
|
Note: Each set of Reliance Jio Coding Questions and Answers will have a specific time restriction.
Question 1:
Problem Statement
Rahul is playing a game, wherein he has multiple colored wooden blocks, stacked one above the other, his task is to remove all the wooden blocks from the stack, without letting them fall and in the minimum number of steps. He can remove one block of color at a time, but he can remove multiple blocks of the same color together. Determine the minimum number of steps in which he can perform this task
Example:- If you remove [red, red] from (white, red, red, white), the resulting array is [white, white
Note- there are only two color blocks – red and white
Input format
- The first line contains an integer n denoting the number of blocks.
- Each n line denotes the color of the wooden block
Constraints
- 1<=n<=700
- >0<=a[i]<=1
Sample Input 1
4
red
white
white
red
Sample Output 1
2
Explanation
Remove [white, white] first
The array will be [red, red]
The remaining numbers can be removed in one strap
Sample Input 2:
4
white
red
white
red
Sample Output 2:
3
Sample Explanation:
The steps are [white, red, white, red] -> [red, white, red] -> [red, red] -> []. Therefore the answer is 3.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<string>arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
int a=0,b=0;
bool start=false;
for(int i = 0; i < n; i++)
{
if(arr[i] == "white")
{
if (!start)
{
start = true;
}
}
else
{
if (start)
{
a++;
start = false;
}
}
}
if (start) a++;
start = false;
for (int i = 0; i < n; i++)
{
if (arr[i] == "red")
{
if (!start)
{
start = true;
}
}
else
{
if (start)
{
b++;
start = false;
}
}
if (start) b++;
}
cout << min(a+1,b+1) << endl;
return 0;
}n = int(input())
arr = []
for i in range(n):
arr.append(input())
a, b = 0, 0
start = False
for i in range(n):
if arr[i] == "white":
if not start:
start = True
else:
if start:
a += 1
start = False
if start:
a += 1
start = False
for i in range(n):
if arr[i] == "red":
if not start:
start = True
else:
if start:
b += 1
start = False
if start:
b += 1
print(min(a + 1, b + 1))
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String arr[]=new String[n];
for(int i=0;i<n;i++)
arr[i]=sc.next();
int a=0,b=0;
boolean flag=false;
for(int i=0;i<n;i++)
{
if(arr[i].equals("white"))
{
if(!flag)
flag=true;
}
else
{
if(flag)
{
a++;
flag=false;
}
}
}
if(flag)
a++;
flag=false;
for(int i=0;i<n;i++)
{
if(arr[i].equals("red"))
{
if(!flag)
flag=true;
}
else
{
if(flag)
{
b++;
flag=false;
}
}
if(flag)
b++;
}
System.out.println(Math.min(a+1,b+1));
}
}
Question 2: Iron Magnet
Problem Statement
We know iron behaves like magnets when all the north and the south sides are placed accordingly in a balanced way while the north comes first and then the south. Now if you are given the distribution of the north and the south poles inside the iron metal piece, you have to say how many swaps are needed to turn it into an iron, if possible, otherwise, print -1.
Input Format:
A string consisting of N and S as north and south poles.
Output Format:
An integer denoting the number of poles will be needed.
Sample Input: SNNSN
Output: 3
Output Description: After we balance the iron in the way NSNNSNSS, we will get a piece of metal that will be balanced as a magnet.
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
int main()
{
int n,sum=0,sum2=0,ans=0;
cin>>n;
vector v(n);
for(int i=0;i< n;i++) { cin>>v[i];
sum+=v[i];
}
sort(v.begin(),v.end(),greater());
sum/=2;
while(sum2<=sum && ans< n)
{
sum2+=v[ans];ans++;
}
cout<< ans;
}s=input()
ans=0
if(s[0]!="N"):
ans+=1
s="N"+s
print(ans+abs(s.count("N")-s.count("S")))
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String str=sc.next();
int res=0,j=0;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)=='N')
j++;
else
j--;
if(j<0)
{
j++;
res++;
}
}
res=res+j;
System.out.println(res);
}
}
Question 3: Loki’s Mind Stone
Problem Statement:
Loki, the God of mischief can brainwash any living person by touching him/her with his Mind stone, and has decided to break the avengers (a warrior group) to face each other so that they can turn against each other and make Loki’s evil plans easier. Now all the avengers have some amount of strength that is denoted in integers. Loki wants to brainwash the least amount of people possible because he is lazy. But he wants his team of Avengers to win the battle. What is the number of avengers Loki will get brainwashed?
Input Format:
The first line contains an integer n, denoting the number of total avengers the next line contains n space-separated integers denoting the power of each avenger.
Output Format:
One line denotes the total number of avengers brainwashed by Loki’s Mind stone.
Constraints:
2<=n<=10^6
#Test cases
Sample Input:
6
9 3 1 2 4 2
Sample Output:
2
Output Specifications:
Loki can brainwash the avengers with power 9 and 3, or with 9 and 2, or with 9,4, and the rest will be losing cause the cumulative power of the rest avengers is less than the brainwashed total power by Loki.
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
int main()
{
int n,sum=0,sum2=0,ans=0;
cin>>n;
vector v(n);
for(int i=0;i< n;i++) {cin>>v[i];sum+=v[i];}
sort(v.begin(),v.end(),greater());
sum/=2;
while(sum2<=sum && ans< n)
{sum2+=v[ans];ans++;}
cout<< ans;
}
n=int(input())
arr=list(map(int,input().split()))
s=sum(arr)
arr.sort(reverse=True)
dup,sum1,ans=0,0,0
for i in arr:
dup+=i
sum1=s-dup
ans+=1
if(sum1< dup):
break
print(ans)
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];
int sum=0;
for(int i=0;i< arr.length;i++)
{
arr[i]= sc.nextInt();
sum=sum+arr[i];
}
Arrays.sort(arr);
int sum1=0,count=0;
for(int i=arr.length-1;i>= 0;i--)
{
sum1=sum1+arr[i];
sum=sum-arr[i];
count++;
if(sum1> sum)
break;
}
System.out.println(count);
}
}
Question 4: Set Bit
Problem Statement:
You are given an integer, N. You have to turn it into the binary representation of it and find out how many set bits are there in the binary representation.
Input Format:
The first line contains the integer.
Output Format:
One line containing an integer denoting the number of set bits.
Constraints:
1<=N<=10^9
Sample Input:
8
Output:
1
Output Description:
8 in binary is 1000.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,ans=0;
cin>>n;
while(n)
{
n&=(n-1);
ans++;
}
cout<< ans;
}
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int count=0;
while(n!=0)
{
if((n&1)==1)
count++;
n=n>>1;
}
System.out.println(count);
}
}
n=int(input())
ans=0
while(n):
n&=(n-1)
ans+=1
print(ans)
Question 5: Death Note
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 up to 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 kill 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 26 letters, and capital or small letters is not a problem.
Input format:
A number stream denoting the first name’s an encrypted version
Output Format:
Several people dying of this.
Constraints:
1<=stream length<=10^8
Sample Input:
1267
Sample Output:
3
Output Specification:
Two people of the name as and LFG die.
#include<bits/stdc++.h>
using namespace std;
string s;
int ans;
void func(int i,int n)
{
if(i==n-1||i==n)
{
ans++;
return;
}
if(s[i]=='1')
{
func(i+2,n);
}
else if(s[i]=='2'&&s[i+1]<'7') { func(i+2,n); func(i+1,n); } } int main() { ans=0; cin>>s;
func(0,s.length());
cout<<ans;
}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);
}
}
def solve(s,n):
if n == 0 or n == 1 :
return 1
ans = 0
if s[n-1] > "0":
ans = solve(s,n-1)
if (s[n - 2] == '1' or (s[n - 2] == '2' and s[n - 1] < '7') ) :
ans+= solve(s, n - 2)
return ans
s=input()
print(solve(s,len(s)))
Question 6: Choco and chocolate
Problem Statement:
Choco, a chocolate lover, has N amount of money with him. He wants to buy as much chocolate as possible. So, he goes to a chocolate shop “Handyman ”. Mike, the owner of “Handyman ” has different types of chocolate in his store (represented by a character) placed in a row.
Mike, give an offer to Choco that he can buy a selected type of chocolate for free and need to pay for the other types of chocolates and Choco can only buy consecutive chocolates.
Now, you need to write a code to find the maximum amount of chocolates Choco can get by selecting the chocolates optimally.
Input format:-
1st line contains 2 space-separated integers A and B denoting the number of chocolates and the amount of money Choco has.
The 2nd line contains A chocolates represented by a string. All chocolates are represented by lowercase alphabets.
The 3rd line represents 26 space-separated integers representing the cost to buy the chocolates.
[The first integer represents the cost of the chocolate of type ‘a’, 2nd integer represents the cost of the chocolates of type ‘b’, and so on]
Output format:
Print the maximum number of chocolates Choco can buy.
Constraints:
1<=A<=10^5
1<=B<=10^9
1<=cost of chocolate<=10^9
Sample Input 1:
6 10
Rabida
5 4 4 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Sample output 1:
4
Explanation:
Choco can select the chocolate of type ‘a’ for free and start buying from index 0 and if he buys “AABC” then he has to pay less (0+0+4+4=8) than the total money he has.
This is the maximum number of chocolates he can get in this case.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;cin>>n>>m;
string s,s1;cin>>s;
cin.ignore();
getline(cin,s1);
istringstream ss(s1);
vector<int> a; vector<char> a1;
while(ss)
{
string w; ss>>w;
if(w=="") break;
a.push_back(stoi(w));
}
map<char,int> mm;
for(auto i:s)
if(mm[i]==0)
{mm[i]++;a1.push_back(i);}
int t=0;
for(auto i:a1)
{
vector<int> a2;
for(auto i1:s)
{
if(i1==i) a2.push_back(0);
else a2.push_back(a[i1-97]);
}
int l=0,su=0;
for(int i2=0;i2< n;i2++)
{
if(l==i2) su+=a2[i2];
else su+=a2[i2];
if(su>m)
{while(su>m && l<=i2)
{su-=a2[l];l++;}}
if(i2-l+1>t) t=i2-l+1;
}
}
cout<< t;
}
import java.util.*;
class Main{
public static int solve(int n,int amnt,String s,int[] price){
int[] freq=new int[26];
char[] ch=s.toCharArray();
int temp=0,ans=0,maxFreq=0,st=0;
for(int i=0;i< n; i++){
int indx=ch[i]-'a';
freq[indx]+=price[indx];
temp+=price[indx];
maxFreq=Math.max(maxFreq,freq[indx]);
if(temp-maxFreq> amnt){
while(temp> amnt){
boolean b=false;
int tempIndx=ch[st]-'a';
if(maxFreq==freq[tempIndx]){
b=true;
}
temp-=price[tempIndx];
freq[tempIndx]-=price[tempIndx];
st++;
if(b){
maxFreq=0;
for(int j=0;j< 26;j++){
maxFreq=Math.max(freq[j],maxFreq);
}
}
if(temp-maxFreq< amnt){
break;
}
}
}
ans=Math.max(ans,i-st+1);
}
return ans;
}
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int n=sc.nextInt();
int amnt=sc.nextInt();
String s=sc.next();
int[] price=new int[26];
for(int i=0;i< n;i++){
price[i]=sc.nextInt();
}
System.out.println(solve(n,amnt,s,price));
}
}
n,m=map(int,input().split())
s=input().strip()
a=list(map(int,input().split()))
s1=set()
for i in s:
if i not in s1:
s1.add(i)
s1=list(s1)
t=0
for i in s1:
a1=[]
for i1 in s:
if i1==i:
a1.append(0)
else:
a1.append(a[ord(i1)-97])
l=0
su=0
for i2 in range(n):
if l==i2:
su=a1[i2]
else:
su+=a1[i2]
if su>m:
while su> m and l<= i2:
su-=a1[l]
l+=1
if (i2-l+1)>t:
t=(i2-l+1)
print(t)
Question 7: Number with 2
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:
The first line, containing n denotes 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 the third number will be 32
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
cout<<(n-1)*10+2;
return 0;
}
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);
}
}
n=int(input()) print((n-1)*10+2)
Question 8: Vowel Encryption
Problem Statement:
There is an encryption game going on. You will be given a number. If a digit is prime, it will take a vowel. Otherwise, it will take a consonant value.
By this process, you have to make the string the lexicographically smallest possible. For a given number, print the output as a string.;
Input Format:
An integer n denotes the number.
Output Format:
The encrypted word.
Sample Input:
123421
Sample Output:
baecab
#include<bits/stdc++.h>
using namespace std;
map<char,char> M;
map<int,bool> prime;
int main()
{
prime[2]=true;
prime[3]=true;
prime[5]=true;
prime[7]=true;
char vow[]={'a','e','i','o','u'};
char con[]={'b','c','d','f','g','h'};
int jv=0,jc=0;
string s;
cin>>s;
for(auto i:s)
{
if(prime[i-'0'])
{
if(M[i]){}
else {M[i]=vow[jv];jv++;}
}
else if(M[i]){}
else {M[i]=con[jc];jc++;}
}
for(auto i:s) cout<< M[i];
}
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String vowel="aeiou";
char arr[]=new char[10];
arr[2]='a';
arr[3]='e';
arr[5]='i';
arr[7]='o';
char ch='b';
for(int i=1;i< arr.length;i++)
{
if(vowel.indexOf(ch)!=-1)
{
ch++;
continue;
}
else if(arr[i]==0)
{
arr[i]=(char)ch++;
}
}
}
int temp=n;
int res=0;
while(temp!=0)
{
res=res*10+temp%10;
temp=temp/10;
}
int i=1;
while(res!=0)
{
System.out.print(arr[res%10]);
res=res/10;
}
}
s=input()
res=[]
x,y=0,0
v="aeiou"
c="bcdfgh"
p="2357"
ans=sorted(set(s))
for i in ans:
if i in p:
res.append(v[x])
x+=1
else:
res.append(c[y])
y+=1
for i in s:
print(res[ans.index(i)],end="")
Question 9: Jack’s Text
Problem Statement:
Jack is learning to type English from the beginning and he is making an error of repeating the same words in his texts over WhatsApp. Write a function that will take input for the text sent to you and then keep only the unique texts.
Note that, the uniqueness is about being word specific, not position, there is nothing but alphabets in the sentences, and words are separated only with white space.
Constraints:
Words in line<=10^5
Alphabets in the words<=20
Sample Input:
Send the image sent to to to me
Output:
Send the mage to me
#include<bits/stdc++.h>
using namespace std;
map<string,bool> m;
int main()
{
string s,s1; getline(cin,s);s1=s;
transform(s.begin(), s.end(), s.begin(), ::tolower);
istringstream ss(s),ss1(s1);
while(ss)
{
string w,w1;ss>> w;ss1>> w1;
if(m[w]==false) cout<< w1<<" ";
m[w]=true;
}
}
import java.util.*;
class Solution
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
String arr[]=str.split(" ");
String first=arr[0];
arr[0]=arr[0].toLowerCase();
LinkedHashMap<String,Boolean> map=new LinkedHashMap<String,Boolean>();
for(int i=0;i< arr.length;i++)
map.put(arr[i],true);
Set s=map.entrySet();
Iterator itr=s.iterator();
System.out.print(first+" ");
int j=0;
while(itr.hasNext())
{
Map.Entry m=(Map.Entry)itr.next();
if((Boolean)m.getValue()==true&&j==1)
System.out.print(m.getKey()+" ");
j=1;
}
}
}
arr=list(input().split())
dup=[]
ans=""
for i in arr:
if i not in dup:
dup.append(i)
ans+=i+" "
print(ans)
Question 10: Copycat
Ashish was copying from Rahit in the exam. So, Rahit told him to change the answers a little bit so that the examiner cannot find the fraud. But silly Ashish in the way started to change all the answers that were needed. He shuffled the letters in each word in a way where the maximum number of letters was misplaced.
For a given word, find the maximum difference that Ashish can generate between his answer and Rohit’s answer.
Suppose Rahit wrote “car” for an answer, Ashish can write “acr” with difference 2, or “arc” with difference 3.
Note That: The letters are all in lowercase.
Input Format:
The first line contains an integer n, the number of words.
Then, n numbers of lines as the query words.
Output:
N number of lines with an integer each denoting possible maximum difference.
Sample Input:
4
abababa
bbj
kj
kk
Sample Output:
6
2
2
0
#include<bits/stdc++.h>
using namespace std;
string s,s1;
int n;
int func()
{
if(n<=1) return 0;
int ans=0,c=0;
sort(s.begin(),s.end());
for(int i=0;i< n;i++)
if(s1[i]!=s[i]) c++;
ans=max(ans,c);
c=0;
while(next_permutation(s.begin(),s.end()))
{
for(int i=0;i< n;i++)
if(s1[i]!=s[i]) c++;
ans=max(ans,c);
c=0;
}
return ans;
}
int main()
{
int t;
cin>> t;
while(t--)
{
cin>> s;
s1=s;
n=s.length();
cout<< func()<< endl;
}
return 0;
}
import java.util.*;
class Solution
{
public static String swapString(String s,int i,int j){
char[]b=s.toCharArray();
char temp;
temp=b[i];
b[i]=b[j];
b[j]=temp;
return String.valueOf(b);
}
public static void generatePermutation(String s,int start,int end,HashSet<String>set){
if(start==end-1)
set.add(s+" ");
else{
for(int i=start;i< end;i++){
s=swapString(s,start,i);
generatePermutation(s,start+1,end,set);
s=swapString(s,start,i);
}
}
}
public static int maxDiff(String str,String s){
int c=0;
for(int i=0;i< s.length();i++){
if(s.charAt(i)==str.charAt(i));
else
c++;
}
return c;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String[]a=new String[n];
for(int i=0;i< n;i++){
a[i]=sc.next();
}
for(int i=0;i< n;i++){
HashSet<String>set=new HashSet<String>();
String s=a[i];
generatePermutation(s,0,s.length(),set);
int max=0;
int k=0;
for(String str:set){
k= maxDiff(str,s);
max=Math.max(max,k);
}
System.out.println(max);
}
}
}
from itertools import permutations
def solve(x,n):
ans=0
for i in permutations(x):
c=0
for j in range(n):
if(x[j]!=i[j]): c+=1
ans=max(ans,c)
return ans
t=int(input())
for i in range(t):
s=input()
print(solve(s,len(s)))

Login/Signup to comment