Zycus Coding Questions and Answers
Zycus Coding Questions with Solutions
In this page, you will find out Zycus Coding Questions and Answers asked in Online Assessment and Technical Interview involved in the Hiring Process of the Company.
By the end of Zycus Coding Questions and Answers page you’ll get FAQ’s related to Zycus Recruitment Process like Job Profile, CTC Offered, Steps involved in the recruitment process, etc. of the company.
Zycus Coding Questions and Answers
Question 1: Stars Between Bars
Given a string s consisting of stars “*” and bars “|” ,an array of starting indices starIndex,and an array of ending indices endIndex,determine the number of stars between any two bars within the substrings between the two indices inclusive . NOTE that in this problem indexing starts at 1.
- A Star is represented as an asterisk [*=ascii decimal 42]
- A Bar is represented as a Pipe [“|”=ascii decimal 124]
Example
s=’|**|*|’
startIndex=[1,1]
endIndex=[5,6]
- For the first pair of indices (1,5) the substrings is “|**|*” . There are 2 stars between a pair of bars
- For the second pair of indices (1,6) the substring is “|**|*|” and there are 2+1=3 stars in between the bars.
- Both of the answers are returned to the array [2,3].
Constraints
- 1<=n<=105
- 1<=StartInde[i]<=endIndex[i]
- Each Character of s is either “*” or “|”
Input Format for Custom testing
First line contains a string S the next line contains an integer n , the no.of elements in startIndex. Each line i of the n subsequent lines contains an integer of startIndex.the next line contains an integer n , the no.of elements in endIndex. Each line i of the n subsequent lines contains an integer of endindex
Sample Input
*|*| → s=”*|*|”
1 → startindex[] size=1
1 → startindex= 1
1 → endindex[] size=1
3 → endindex=3
Sample output:
0
Explanation :
The substring from index =1 to index=3 is “*|*” . there is no consecutive pair of bars in this string.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int n; cin >> n; int st[n], ed[n]; for (int i = 0; i < n; i++){ cin >> st[i]; st[i]--; } cin>>n; for (int i = 0; i < n; i++){ cin >> ed[i]; ed[i]--; } vector<int> bars; for (int i = 0; i < s.length(); i++){ if (s[i] == '|') bars.push_back(i); } for (int i = 0; i < n; i++){ int idx = lower_bound(bars.begin(),bars.end(),st[i]) - bars.begin(); st[i] = bars[idx]; idx = lower_bound(bars.begin(),bars.end(),ed[i]) - bars.begin(); if(idx == 0 || bars[idx]==ed[i]) continue; ed[i] = bars[idx-1]; } int sz = s.length(); int starCt[sz] = {0}; if(s[0] == '*') starCt[0] = 1; for(int i =1;i<sz;i++){ starCt[i] = starCt[i-1] + (s[i]=='*'); } for(int i =0;i<n;i++){ if(st[i]>=ed[i]){ cout<<0<<endl; } else{ int ans = starCt[ed[i]]; if(st[i]>0) ans-=starCt[st[i]-1]; cout<<ans<<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(); int n=sc.nextInt(); int startIndex[]=new int[n]; int endIndex[]=new int[n]; for(int i=0;i<n;i++) startIndex[i]=sc.nextInt(); for(int i=0;i<n;i++) endIndex[i]=sc.nextInt(); int count=0; for(int i=0;i<n;i++){ count=0; String sub=str.substring(startIndex[i]-1,endIndex[i]); int start= sub.indexOf("|"); int end=sub.lastIndexOf("|"); for(int j=start;j<end;j++) if(sub.charAt(j)=='*') count++; System.out.print(count+" "); } } }
s=input() start=[] end=[] n=int(input()) for i in range(n): start.append(int(input())) for i in range(int(input())): end.append(int(input())) for i in range(n): Str=s[start[i]-1:end[i]] print(Str.strip('*').count('*'))
Question 2 : Coloured Zenga
Problem Statement :
Rahul is playing a game, wherein he has multiple coloured wooden blocks, stacked one above the other, his task is to remove all the wooden blocks from the stack, without letting it fall and in the minimum number of steps. He can remove one block of a colour at a time, but he can remove multiple blocks of the same colour together. Determine the minimum number of steps in which he can perform this task.
For example, if you remove [red,red] from (white,red,red,white), the resulting array is [white,white].
Note- there are only two colour blocks – red and white
Function description :
Complete the minMoves function in the provided editor. It contains the following parameters:
Parameters:
Name | Type | Description |
---|---|---|
N | Integer | No. of Wooden blocks |
Array[ ] | Integer Array | Array of Blocks. |
Input format :
The first line contains an integer n denoting the number of blocks. Each n line denotes the colour of the wooden block .
Constraints :
1<=n<=700
0<=a[i]<=1
Sample input 1 :
4
red
white
white
red
Sample Output 2 :
2
Explanation :
Remove [white,white] first The array will be [red,red] The remaining numbers can be removed in one strap .
Sample Input 1:
4
white
red
white
red
Sample Output 1:
3
Sample Explanation:
0
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; }
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)); } }
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))
Question 3: Fantasy Premier League
Problem statement :
Ramesh loves to bet and also loves football, so he created a fantasy football team in FPL. He chose Rashford in his team. You are given a string in which each index denotes a match and it consists of characters: Y, G, A. G means goal scored and the player is awarded 4 points, for A 3 points, and for every Y, 1 point is deducted.
Calculate the points scored by rashford
Constraints:
- 0<n<105
Sample case 0:
Sample input 0:
EHH → erica=”EHH”
EME → bob=”EME”
Sample output 0:
Erica
Explanation 0:
Erica’s score is , 1+5+5=11
Bob’s score is , 1+3+1=5
So Erica is the winner
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here int t; t = 1; while (t--) { string erica, bob; cin >> erica >> bob; int erica_score = 0, bob_score = 0; for (int i = 0; i < erica.length(); i++) { if (erica[i] == 'E') erica_score += 1; else if (erica[i] == 'M') erica_score += 3; else erica_score += 5; } for (int i = 0; i < bob.length(); i++) { if (bob[i] == 'E') bob_score += 1; else if (bob[i] == 'M') bob_score += 3; else bob_score += 5; } if (erica_score > bob_score) { cout << "Erica\n"; } else if (erica_score < bob_score) { cout << "Bob\n"; } else { cout << "Tie\n"; } } return 0; }
import java.util.*; public class CoderFriends { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String erica = sc.next(); String bob = sc.next(); int ericaScore = 0; int bobScore = 0; for (int i = 0; i < erica.length(); i++) { if (erica.charAt(i) == 'E') ericaScore = ericaScore + 1; else if (erica.charAt(i) == 'M') ericaScore = ericaScore + 3; else if (erica.charAt(i) == 'H') ericaScore = ericaScore + 5; } for (int i = 0; i < bob.length(); i++) { if (bob.charAt(i) == 'E') bobScore = bobScore + 1; else if (bob.charAt(i) == 'M') bobScore = bobScore + 3; else if (bob.charAt(i) == 'H') bobScore = bobScore + 5; } if (bobScore == ericaScore) System.out.println("Tie"); else if (bobScore > ericaScore) System.out.println("Bob"); else System.out.println("Erica"); } } }
erica=input() bob=input() erica_score=erica.count("E")+erica.count("M")*3+erica.count("H")*5 bob_score=bob.count("E")+bob.count("M")*3+bob.count("H")*5 if(erica_score==bob_score): print("Tie") elif(erica_score>bob_score): print("Erica") else: print("Bob")
Question 4 : Share Holder (R -> Hard)
Problem Statement :
Ratan is a crazy rich person. And he is blessed with luck, so he always made the best profit possible with the shares he bought. That means he bought a share at a low price and sold it at a high price to maximize his profit. Now you are an income tax officer and you need to calculate the profit he made with the given values of stock prices each day. You have to calculate only the maximum profit Ratan earned.
Note that:
Ratan never goes into loss.
Example 1 :
Price=[1,6,2]
Ratan buys it on the first day and sells it on the second.
Example 2 :
Price=[9,8,6]
The Price always went down, Ratan never bought it.
Input Format:
First line with an integer n, denoting the number days with the value of the stack
Next n days, telling the price of the stock on that very day.
Output Format:
Maximum profit done by Ratan in a single line.
Constraints:
Number of days <=10^8
Sample Input for Custom Testing:
STDIN
7
1
9
2
11
1
9
2
Sample Output :
10
Explanation :
The maximum profit possible is when Ratan buys it in 1 rupees and sells it in 11.
#include <bits/stdc++.h> using namespace std; int solve(vector < int > v) { int n = v.size(); if (n == 0) return 0; int mx = v[0]; for (int i = 1; i < n; i++) mx = max(mx, v[i]); if (mx <= 0) return 0; int mxSum = 0; int cSum = 0; for (int i = 0; i < n; i++) { cSum += v[i]; if (cSum < 0) cSum = 0; mxSum = max(mxSum, cSum); } return mxSum; } int main() { int n; cin >> n; int price[n]; for (int i = 0; i < n; i++) cin >> price[i]; vector < int > diff; for (int i = n-2; i >= 0 ; i--) diff.push_back(price[i+1] - price[i]); int ans = solve(diff); if(ans < 0) cout << 0 << endl; else cout<< ans << endl; }
import java.util.*; public class PrepInsta { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int price[] = new int[n]; for(int i=0;i < n;i++) { price[i] = sc.nextInt(); } Vector < Integer > diff = new Vector<>(); for(int i=n-2;i >=0;i--) { diff.add(price[i+1]-price[i]); } int ans = solve(diff); if(ans < 0) { System.out.println(0); }else { System.out.println(ans); } } private static int solve(Vector < Integer > v) { int n = v.size(); if(n==0) { return 0; } int mx = v.get(0); for(int i=1;i < n;i++) { mx = Math.max(mx, v.get(i)); } if(mx <= 0) { return 0; } int mxSum=0,csum=0; for(int i=0;i < n;i++) { csum+=v.get(i); if(csum < 0) csum=0; mxSum = Math.max(csum, mxSum); } return mxSum; } }
def func(diff): n=len(diff) if n==0: return 0 mx=max(diff) if mx <= 0: return 0 mxS=0 cS=0 for i in diff: cS+=i if cS <= 0: cS=0 mxS=max(cS,mxS) return mxS n=int(input()) arr=[] diff=[] ans=[0] for i in range(n): arr.append(int(input()))c++ for i in range(n-1): diff.append(arr[i+1]-arr[i]) ans=func(diff) if ans < 0: print("0") else: print(ans)
Question 5 : Elements of Matrix
Problem Statement
You are required to input the size of the matrix then the elements of matrix, then you have to divide the main matrix in two sub matrices (even and odd) in such a way that element at 0 index will be considered as even and element at 1st index will be considered as odd and so on. then you have sort the even and odd matrices in ascending order then print the sum of second largest number from both the matrices
Example
- enter the size of array : 5
- enter element at 0 index : 3
- enter element at 1 index : 4
- enter element at 2 index : 1
- enter element at 3 index : 7
- enter element at 4 index : 9
Sorted even array : 1 3 9
Sorted odd array : 4 7
7
#include<bits/stdc++.h> using namespace std; int main () { int arr[100]; int length, i, j, oddlen, evenlen, temp, c, d; int odd[50], even[50]; cout << "enter the length of array : "; cin >> length; for (i = 0; i < length; i++) { cout << "Enter element at " << i << " index : "; cin >> arr[i]; } if (length % 2 == 0) { oddlen = length / 2; evenlen = length / 2; } else { oddlen = length / 2; evenlen = (length / 2) + 1; } for (i = 0; i < length; i++) // seperation of even and odd array { if (i % 2 == 0) { even[i / 2] = arr[i]; } else { odd[i / 2] = arr[i]; } } for (i = 0; i < evenlen - 1; i++) // sorting of even array { for (j = i + 1; j < evenlen; j++) { temp = 0; if (even[i] > even[j]) { temp = even[i]; even[i] = even[j]; even[j] = temp; } } } for (i = 0; i < oddlen - 1; i++) // sorting of odd array { for (j = i + 1; j < oddlen; j++) { temp = 0; if (odd[i] > odd[j]) { temp = odd[i]; odd[i] = odd[j]; odd[j] = temp; } } } cout << "\nSorted even array : "; // printing even array for (i = 0; i < evenlen; i++) { cout << even[i] << " "; } cout << "\n"; cout << "Sorted odd array : "; // printing odd array for (i = 0; i < oddlen; i++) { cout << odd[i] << " "; } cout << endl; cout << even[evenlen - 2] + odd[oddlen - 2]; // printing final result }
import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; public class Main { public static void main (String[]args) { Scanner sc = new Scanner (System.in); System.out.print ("Enter size of array : "); int arrsize = sc.nextInt (); int[] main = new int[arrsize]; ArrayList < Integer > even = new < Integer > ArrayList (); ArrayList < Integer > odd = new < Integer > ArrayList (); System.out.println ("Enter " + arrsize + " Elements"); for (int i = 0; i < arrsize; i++) main[i] = sc.nextInt (); for (int i = 0; i < arrsize; i++) { if (i % 2 == 0) even.add (main[i]); else odd.add (main[i]); } Collections.sort (even); Collections.sort (odd); System.out.println ("Sorted even array "); for (int e:even) System.out.print (e + " "); System.out.println (); System.out.println ("sorted odd array "); for (int e:odd) System.out.print (e + " "); System.out.println (); int evensec = even.get (even.size () - 2); int oddsec = odd.get (odd.size () - 2); System.out.println ("Second Largest Element in Even List is:" + evensec); System.out.println ("Second Largest Element in Odd List is:" + oddsec); System. out.println ("Sum Of Second Largest Element Of Odd and Even List:" + (evensec + oddsec)); } }
array = [] evenArr = [] oddArr = [] n = int(input("Enter the size of the array:")) for i in range(0,n): number = int(input("Enter Element at {} index:".format(i))) array.append(number) if i % 2 == 0: evenArr.append(array[i]) else: oddArr.append(array[i]) evenArr = sorted(evenArr) print("Sorted Even Array:", evenArr[0:len(evenArr)]) oddArr = sorted(oddArr) print("Sorted Odd Array:", oddArr[0:len(oddArr)]) print(evenArr[1] + oddArr[1]) evenArr = sorted(evenArr) print("Sorted Even Array:", evenArr[0:len(evenArr)]) oddArr = sorted(oddArr) print("Sorted Odd Array:", oddArr[0:len(oddArr)]) print(evenArr[-2] + oddArr[-2])
Question 6 : Game Of Clicks [ R->Hard ]
Problem Statement :
Sahil watches TV all day and gets bored. He started playing this dumb game of identifying minimum number of inputs needed to reach a channel. As his cousin, you have to help him, but you live far from his house. So you decide to write a code that will ask Sahil for some inputs and give outputs respectively.
Here are the problems you need to keep in mind :
- There are 13 buttons on his remote: 10 buttons for the numbers (0-9) to form integers denoting respective channel index, “Up channel” button and “ Down channel” button for going i +1th channel and i-1th channel from i respectively, and a “Last viewed” button to see what’s the last channel before it.
- The number buttons allow you to jump directly to a specific channel (Ex: to go to channel 172 by typing 1,7,2).
- If the channel which you are in is ith and that is the max channel index possible, by Up channel, you will reach the first channel possible. Same goes for the down channel button. You can go to the highest channel possible if you go down from the lowest channel possible.
- Sahil can get from one channel to the next in one of the two ways.
- Sahil’s parents have set some parental control on some channels on Aniruth’s television. The “Up Channel “ and “Down buttons” buttons skip these channels as these channels are not viewable.
- Given a list of channels to view, the lowest channel, the highest channel, and a list of blocked channels, your program should return the minimum number of clicks necessary to get through all the shows that Anirudh would like to match.
Input Format :
- First line is the lowest Channel
- Second-line is the highest Channel
- Followed by a number of blocked channels B,
and the next B lines contain the actual blocked channels. - Followed by the number of Channels to view V, and the next V lines contain the actual channels to view.
Constraints :
- The lowest channel on the television will be greater than 0. and less than or equal to 10,000.
- The highest channel on the television will be greater than or equal to the lowest channel. and less than or equal to 10.000.
- The list of channels that are blocked on Anirudh’s television. All the channels in this list will be valid channels (greater than or equal to lowest channel, less than or equal 1 to highest channel). Duplicates may be Ignored. The blocked list can be a maximum of 40 channels.
- The sequence that Sahil must view contains between 1 and 50 elements. inclusive. All channels in this sequence are not in the blocked list and are between lowest channel and highest channel. Inclusive.
Sample Input 0:
1
20
2
18
19
5
15
14
17
11
17
Sample output 0:
8
#include<bits/stdc++.h> using namespace std; unordered_map < int, int > m; int l, u; int util(int a, int b) { if (a == b) return 0; if (m[a]) return util(a + 1, b); return 1 + util(a + 1, b); } int func(int b, int prev) { if (b < prev) return min(util(prev, u) + util(l, b) + 1, util(b, prev)); else return min(util(prev, b), util(l, b) + util(prev, u) + 1); } int main() { int flag = 0, ans = 0, prev, prev2; cin >> l >> u; int bn, b; cin >> bn; while (bn--) { cin >> b; m[b]++; } cin >> bn; while (bn--) { cin >> b; if (b > 9 && flag == 0) { ans += 2; flag++; prev = b; } else if (flag == 0) { ans += 1; flag++; prev = b; } else if (prev2 == b) { prev2 = prev; prev = b; ans++; } else { ans += min(b > 9 ? 2 : 1, func(prev, b)); prev2 = prev; prev = b; } } cout << ans; }
def prev(now, l, h, blocked): if now != l: if (now - 1) not in blocked: return now - 1 else: return prev(now - 1, l, h, blocked) else: if h not in blocked: return h else: return prev(h, l, h, blocked) def next(now, l, h, blocked): if now != h: if (now + 1) not in blocked: return now + 1 else: return next(now + 1, l, h, blocked) else: if l not in blocked: return l else: return next(l, l, h, blocked) def digits(n): count = 0 while n > 0: n = n // 10 count += 1 return count for i in range(2): if i == 0: l = int(input()) else: h = int(input()) b = int(input()) blocked = [] for i in range(b): blocked.append(int(input())) back = -1 now = -1 c = int(input()) k = 0 for i in range(c): n = int(input()) n1 = digits(n) if now == -1: now = n k += n1 continue if back == n: k += 1 back, now = now, back continue pf = 0 pb = 0 now1 = now prev1 = now for j in range(n1): if j == (n1 - 1): pf = n1 pb = n1 break else: now1 = next(now1, l, h, blocked) pf += 1 prev1 = prev(prev1, l, h, blocked) pb += 1 if now1 == n: break if prev1 == n: break k += pf back = now now = n print(k)
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int l = sc.nextInt(); int h = sc.nextInt(); int b = sc.nextInt(); List blackList = new ArrayList<>(); for (int i = 0; i < b; i++) { blackList.add(sc.nextInt()); } int v = sc.nextInt(); Set validList = new HashSet<>(); for (int i = 0; i < v; i++) { int value = sc.nextInt(); if (!blackList.contains(value)) { validList.add(value); } } int totalLength = 0; for (int value : validList) { totalLength += String.valueOf(value).length(); } System.out.println(totalLength); } }
Question 7 : Airport Authority
Problem Statement -:
In an airport, the Airport authority decides to charge a minimum amount to the passengers who are carrying luggage with them. They set a threshold weight value, say, T, if the luggage exceeds the weight threshold you should pay double the base amount. If it is less than or equal to threshold then you have to pay $1.
Function Description:
Complete the weightMachine function in the editor below. It has the following parameter(s):
Parameters:
Name | Type | Description |
N | Integer | number of luggage |
T | Integer | weight of each luggage |
weights[ ] | Integer array | threshold weight |
Returns: The function must return an INTEGER denoting the required amount to be paid.
Constraints:
- 1 <= N <= 10^5
- 1 <= weights[i] <= 10^5
- 1 <= T <= 10^5
Input Format for Custom Testing:
- The first line contains an integer, N, denoting the number of luggage.
- Each line i of the N subsequent lines (where 0 <= i <n) contains an integer describing the weight of ith luggage.
- The next line contains an integer, T, denoting the threshold weight of the boundary wall.
Sample Cases:
- Sample Input 1
4
1
2
3
4
3 - Sample Output 1
5 - Explanation:
Here all weights are less than threshold weight except the luggage with weight 4 (at index 3) so all pays base fare and it pays double fare.
#include <bits/stdc++.h> using namespace std; long int weightMachine(long int N,long int weights[],long int T) { long int amount=0,i; for(i=0;i<N;i++) { amount++; if(weights[i]>T) { amount++; } } return amount; } int main() { long int N,i,T; cin>>N; long int weights[N]; for(i=0;i<N;i++) { cin>>weights[i]; } cin>>T; cout<<weightMachine(N,weights,T); return 0; }
import java.util.*; class Main { static int weightMachine (int N, int weights[],int T) { int amount = 0, i; for (i = 0; i < N; i++) { amount++; if (weights[i] > T) { amount++; } } return amount; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt (); int weights[]= new int[n]; for(int i=0; i<n; i++) weights[i] = sc.nextInt(); int t = sc.nextInt (); System.out.println (weightMachine(n, weights, t)); } }
def weightMachine(N,weights,T): amount=0 for i in weights: amount+=1 if(i>T): amount+=1 return amount N=int(input()) weights=[] for i in range(N): weights.append(int(input())) T=int(input()) print(weightMachine(N,weights,T))
Question 8 : Help of Prepsters
Problem Statement :
Arnab has given me a challenge. I have to calculate the number of numbers which are less than a certain value n, and have exactly k set bits in its binary form. As you are a Prepster like me, help me write a code that will take input for n and k and give the expected output.
Constraints :
1<=n<=10000
1<=k<=10
Input Format :
First line containing n and k space separated
Output Format :
Number of numbers present in a single line
Sample Input:
7 2
Sample Output:
3
Explanation:
11,110,101 -> These three numbers.
#include <bits/stdc++.h> using namespace std; int n, k, ans, l; map < int, int > m; void func(int i, string s, int L) { // cout<< s<< endl; if (L > l) { return; } if (i == 0 && m[stoull(s, 0, 2)] == 0) { m[stoull(s, 0, 2)]++; ans++; } if (s != "") if (n < stoull(s, 0, 2)) { return; } func(i - 1, s + "1", L + 1); func(i, s + "0", L + 1); } int main() { cin >> n >> k; char res[10000]; itoa(n, res, 2); ans = 0; l = strlen(res); func(k - 1, "1", 1); cout << ans; } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int ans = 0; for (int i = 1; i < n; i++) { if (countSetBits(i) == k) { ans++; } } System.out.println(ans); } private static int countSetBits(int i) { if (i == 0) return 0; else return 1 + countSetBits(i & (i - 1)); } }
ans = 0 n, k = map(int, input().split()) l = len(bin(n)[2:]) def func(i, s, L): global l global ans if L > l: return if i == 0: ans += 1 if s != "": if n < int(s, 2): return func(i - 1, s + "1", L + 1) func(i, s + "0", L + 1) func(k - 1, "1", 1) print(ans)
Question 9 : Maneuvering a Cave Problem
Problem Description
The task is to count all the possible paths from top left to bottom right of a m x n matrix with the constraints that from each cell you can either move only to right or down.
Input:
- First line consists of T test cases. First line of every test case consists of N and M, denoting the number of rows and number of columns respectively.
Output:
- Single line output i.e count of all the possible paths from top left to bottom right of a m x n matrix..
Constraints:
- 1<=T<=100
- 1<=N<=100
- 1<=M<=100
#include<stdio.h> int calc(int x, int y) ; int main() { int a,b; printf("Enter the number of rows of the matrix : "); scanf("%d",&a); printf("Enter the number of columns of the matrix : "); scanf("%d",&b); printf("%d", calc(a,b)); return 0; } int calc(int x, int y) { if (x == 1 || y == 1)// If there is a singular matrix { return 1; } else { return calc(x - 1, y) + calc(x, y - 1); } }
Output Enter the number of rows of the matrix : 3 Enter the number of columns of the matrix : 3 6
#include<bits/stdc++.h> using namespace std; int calc(int x, int y) ; int main() { int a,b,n; cout<<("Enter the number of test cases"); cin>>n; while(n!=0) { cout<<("Enter the number of rows of the matrix : "); cin>>a; cout<<("Enter the number of columns of the matrix : "); cin>>b; cout << "Number of ways - "<< calc(a,b)<<"\n"; n--; } return 0; } int calc(int x, int y) { if (x == 1 || y == 1)// If there is a singular matrix { return 1; } else { return calc(x - 1, y) + calc(x, y - 1); } }
Output Enter the number of test cases 2 Enter the number of rows of the matrix : 2 Enter the number of columns of the matrix : 2 Number of ways - 2 Enter the number of rowa of the matrix : 3 Enter the number of columns of the matrix : 3 Number of ways - 6
import java.util.Scanner; public class Main { static int path(int m , int n) { if(m==1 || n==1) return 1; return path(m-1,n)+path(m,n-1); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a,b,c; System.out.println("Enter test cases : "); c=sc.nextInt(); while(c-- > 0) { System.out.println("Enter number of rows and columns : "); a=sc.nextInt(); b=sc.nextInt(); System.out.println(path(a,b)); } } }
Output Enter number of test cases : 2 Enter number of rows and columns : 3 3 6 Enter number of rows and columns : 4 2 4
a = int(input()) b = int(input()) def calculate(a, b): if a == 1 or b == 1: return 1 else: return calculate(a - 1, b) + calculate(a, b - 1) print(calculate(a, b))
Output 3 3 6
Question 10 : Stocks
Problem Statement – Ratan is a crazy rich person. And he is blessed with luck, so he always made the best profit possible with the shares he bought. That means he bought a share at a low price and sold it at a high price to maximize his profit. Now you are an income tax officer and you need to calculate the profit he made with the given values of stock prices each day. You have to calculate only the maximum profit Ratan earned.
Note that:
- Ratan never goes into loss.
Example 1
- Price=[1,6,2]
- Ratan buys it on the first day and sells it on the second.
Example 2
- Price=[9,8,6]
The Price always went down, Ratan never bought it.
Input Format:
- First line with an integer n, denoting the number days with the value of the stack
- Next n days, telling the price of the stock on that very day.
Output Format:
- Maximum profit done by Ratan in a single line.
Constraints:
- Number of days <=10^8
Sample Input for Custom Testing
STDIN
———–
7
1
9
2
11
1
9
2
Sample Output
10
Explanation
The maximum profit possible is when Ratan buys it in 1 rupees and sells it in 11.
#include<bits/stdc++.h> using namespace std; int solve (vector < int >v) { int n = v.size (); if (n == 0) return 0; int mx = v[0]; for (int i = 1; i < n; i++) mx = max (mx, v[i]); if (mx <= 0) return 0; int mxSum = 0; int cSum = 0; for (int i = 0; i < n; i++) { cSum += v[i]; if (cSum < 0) cSum = 0; mxSum = max (mxSum, cSum); } return mxSum; } int main () { int n; cin >> n; int price[n]; for (int i = 0; i < n; i++) cin >> price[i]; vector < int >diff; for (int i = n - 2; i >= 0; i--) diff.push_back (price[i + 1] - price[i]); int ans = solve (diff); if (ans < 0) cout << 0 << endl; else cout << ans << endl; }
import java.util.*; public class PrepInsta { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int price[] = new int[n]; for (int i = 0; i < n; i++) { price[i] = sc.nextInt(); } Vector < Integer > diff = new Vector < > (); for (int i = n - 2; i >= 0; i--) { diff.add(price[i + 1] - price[i]); } int ans = solve(diff); if (ans < 0) { System.out.println(0); } else { System.out.println(ans); } } private static int solve(Vector < Integer > v) { int n = v.size(); if (n == 0) { return 0; } int mx = v.get(0); for (int i = 1; i < n; i++) { mx = Math.max(mx, v.get(i)); } if (mx <= 0) { return 0; } int mxSum = 0, csum = 0; for (int i = 0; i < n; i++) { csum += v.get(i); if (csum < 0) csum = 0; mxSum = Math.max(csum, mxSum); } return mxSum; } }
def func(diff): n=len(diff) if n==0: return 0 mx=max(diff) if mx<=0: return 0 mxS=0 cS=0 for i in diff: cS+=i if cS<=0: cS=0 mxS=max(cS,mxS) return mxS n=int(input()) arr=[] diff=[] ans=[0] for i in range(n): arr.append(int(input())) for i in range(n-1): diff.append(arr[i+1]-arr[i]) ans=func(diff) if ans<0: print("0") else: print(ans)
FAQs on Zycus Games Coding Questions
Question 1: How do I prepare for a Zycus technical interview?
Applicants must have Good Command in Advanced DSA and Core Computer Science Engineering concepts to pass the Technical Interview of Zycus.
Question 2: In which field Zycus focus on?
The company focuses on digital purchasing, e – invoice processing, expense analysis, online supplier sourcing, contract handling, supplier relationship management, and financial savings tracking.
Question 3: What is the salary of PayPal Sde1?
Question 4: What is Zycus Recruitment Process?
There are 3 Rounds conducted for PayPal Recruitment Process:
- Online Aptitude + Technical Assessment
- Coding Round + Technical Interview
- HR Interview
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