Kotak SDE Coding Questions and Answers

Kotak Mahindra Bank SDE Coding Question and Answer :
In this page we have given the latest coding question and their answers asked in Kotak Mahindra Bank for SDE 1 role.
Kotak Mahindra Bank SDE 1 Coding Questions and Answers
Rounds | Pattern | Time |
---|---|---|
Round 1 | DSA Round test | 60 mins |
Round 2 | DSA + Project Round + CS Fundamental test | 45-60mins |
Round 3 | DSA with Oops test | 45-60 mins |
Round 4 | Hiring Manager Round | 1 – 1.5 hrs |
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 0.
- A Star is represented as an asterisk [*=ascii decimal 42]
- A Bar is represented as a Pipe [“|”=ascii decimal 124]
Example
s=’|**|*|’
n = 2
startIndex=[0,0]
endIndex=[4,5]
- For the first pair of indices (0,4) the substrings is “|**|*” . There are 2 stars between a pair of bars
- For the second pair of indices (0,5) 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 <= StartIndex[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 and endIndex. Each line i of the n subsequent lines contains an integer of startIndex. Each line i of the n subsequent lines contains an integer of endindex.
Sample Input
*|*| → s=”*|*|”
1 → size of startindex[] and endIndex[] is 1.
0 → startindex = 0
2 → endindex = 2
Sample output:
0
Explanation :
The substring from index = 0 to index = 2 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<iostream> #include<stack> #include<vector> #include<algorithm> using namespace std; int main() { string str; cin >> str; int n; cin >> n; vector<int> startIndex(n); vector<int> endIndex(n); for (int i = 0; i < n; i++) { cin >> startIndex[i]; } for (int i = 0; i < n; i++) { cin >> endIndex[i]; } int len = str.length(); vector<int> counter(len, -1); int count = 0; int lastIdx = -1; stack<int> st; for (int i = 0; i < len; i++) { char ch = str[i]; if (ch == '|') { while (!st.empty()) { int idx = st.top(); st.pop(); counter[idx] = i; } } st.push(i); } vector<int> ansArr(n); for (int i = 0; i < n; i++) { int sIndex = startIndex[i]; int eIndex = endIndex[i]; int sCount = 0; if (str[sIndex] != '|') sIndex = counter[sIndex]; if (sIndex == -1 || counter[sIndex] == -1) { ansArr[i] = 0; continue; } while (sIndex < eIndex) { int nextIdx = counter[sIndex]; if ((nextIdx != -1) && (nextIdx <= eIndex)) { sCount += nextIdx - sIndex - 1; } sIndex = nextIdx; } ansArr[i] = sCount; } for (int ele : ansArr) { cout << ele << " "; } cout << endl; return 0; }
import java.util.*; class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); String str = scn.next(); int n = scn.nextInt(); int startIndex[] = new int[n]; int endIndex[] = new int[n]; for(int i = 0; i < n; i++) { startIndex[i] = scn.nextInt(); } for(int i = 0; i < n; i++) { endIndex[i] = scn.nextInt(); } int len = str.length(); int counter[] = new int[len]; int count = 0; int lastIdx = -1; Arrays.fill(counter, -1); Stack<Integer> st = new Stack<>(); for(int i = 0; i < len; i++) { char ch = str.charAt(i); if(ch == '|') { while(!st.empty()) { int idx = st.pop(); counter[idx] = i; } } st.push(i); } int ansArr[] = new int[n]; for(int i = 0; i < n; i++) { int sIndex = startIndex[i]; int eIndex = endIndex[i]; int sCount = 0; if(str.charAt(sIndex) != '|') sIndex = counter[sIndex]; if(sIndex == -1 || counter[sIndex] == -1) { ansArr[i] = 0; continue; } while(sIndex < eIndex) { int nextIdx = counter[sIndex]; if((nextIdx != -1) && (nextIdx <= eIndex)) { sCount += nextIdx - sIndex - 1; } sIndex = nextIdx; } ansArr[i] = sCount; } for(int ele : ansArr) { System.out.print(ele + " "); } } }
str = input() n = int(input()) startIndex = [] endIndex = [] for i in range(n): startIndex.append(int(input())) for i in range(n): endIndex.append(int(input())) len_str = len(str) counter = [-1] * len_str count = 0 lastIdx = -1 st = [] for i in range(len_str): ch = str[i] if ch == '|': while st: idx = st.pop() counter[idx] = i st.append(i) ansArr = [] for i in range(n): sIndex = startIndex[i] eIndex = endIndex[i] sCount = 0 if str[sIndex] != '|': sIndex = counter[sIndex] if sIndex == -1 or counter[sIndex] == -1: ansArr.append(0) continue while sIndex < eIndex: nextIdx = counter[sIndex] if nextIdx != -1 and nextIdx <= eIndex: sCount += nextIdx - sIndex - 1 sIndex = nextIdx ansArr.append(sCount) for ele in ansArr: print(ele, end=" ")
Question 2 : Duplicates
The principal has a problem with repetitions. Everytime someone sends the same email twice he becomes angry and starts yelling. His personal assistant filters the mails so that all the unique mails are sent only once, and if there is someone sending the same mail again and again, he deletes them. Write a program which will see the list of roll numbers of the student and find how many emails are to be deleted.
Input Format:
- First line takes n, which is the total no. of mails recieved.
- Second line takes the n no. of email id as input./li>
Output Format:
Total no. of duplicate email id’s to be deleted.
Constraints:
- 1 <= n <= 10^4
Sample input:
- 6
- 1 3 3 4 3 3
Sample output
- 3
#include<bits/stdc++.h> using namespace std; map<int,int> m; int main() { int n,a,ans=0; cin>>n; while(n--) { cin>>a; m[a]++; if(m[a]>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(); TreeSet list=new TreeSet<>(); for(int i=0;i<n;i++) list.add(sc.nextInt()); System.out.println(Math.abs(n-list.size())); } }
def countDuplicate(numbers): c=0 for i in set(numbers): if numbers.count(i)>1: c+=numbers.count(i)-1 return c n=int(input()) numbers=[] numbers = list(map(int, input().split())) print(countDuplicate(numbers))
Question 3 : Last student’s ID
Problem Statement :
There is an id code that is supposed to be given to all the aspirants of an exam. It is actually a substring of a given string. That means, the authority takes a string and then assigns all the unique substrings to all the students. Suppose there is a string “abcde”, so the ids of the students will be “a”,”b”,”c”,”d”,”e”,’ab”,”abc”,”abcd”,”abcde”,”bc”,”bcd”,”bcde”,”cd”,”cde”,”de”.
The students are standing in a line according to the lexicographic order of their given ids. You have to find out the id of the last student for the given input string from which the ids are generated.
Input Format:
Single line with the id generating string
Output format:
The last id as per lexicographical order
Constraints:
Number of characters in the string<=10^9
Sample Input:
abdc
Sample output:
dc
Explanation:
The last student will be with the id dc. The order will be
abdc
a
ab
abd
abdc
b
bd
bdc
c
d
dc
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector < string > v; for (int i = 0; i < s.length(); i++) { v.push_back(s.substr(i, s.length() - i)); //cout<<v[i]<<endl; } sort(v.begin(), v.end(), greater < string > ()); cout << v[0]; }
import java.util.*; public class Main { public static String maxString(char set[]) { int n = set.length; String temp = ""; TreeSet < String > list = new TreeSet < > (); for (int i = 0; i < n; i++) { temp = ""; for (int j = i; j < n; j++) { temp = temp + set[j]; list.add(temp); } } return list.last(); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); char arr[] = str.toCharArray(); System.out.println(maxString(arr)); } }
s = input() j = 1 c = 0 while j < len(s): if ord(s[c]) < ord(s[j]): c = j j += 1 print(s[c:])
Question 4 :Make It Palindrome
Problem Statement :
You’re given a string, you’ve to print additional characters needed to make that string a palindrome.
A Palindrome is a sequence of characters that has the property of reading the same in either direction.
Input :
abede
Output :
ba
Sample Input :
abcfe
Sample output :
fcba
#include <bits/stdc++.h> using namespace std; bool Pal(string s) { string s1 = s; reverse(s1.begin(), s1.end()); return s1 == s; } int main() { string s; getline(cin, s); int i; for (i = 0; i < s.length() - 1; i++) if (Pal(s.substr(i, s.length() - i))) break; s = s.substr(0, i); reverse(s.begin(), s.end()); cout << s; }
import java.util.*; public class Main { public static boolean isPalindrome(String str) { char arr[] = str.toCharArray(); for (int i = 0, j = arr.length - 1; i < j; i++, j--) if (arr[i] != arr[j]) return false; return true; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); String res = ""; for (int i = 0; i < str.length(); i++) { if (isPalindrome(str.substring(i, str.length()))) { res = str.substring(0, i); break; } } System.out.println(new StringBuilder(res).reverse()); } }
def ispalindrome(s): return s == s[::-1] def solve(s): if ispalindrome(s): return None for i in range(len(s)): x = s[:i][::-1] if ispalindrome(s + x): return x s = input() print(solve(s))
Question 5: Class Monitor
Problem Statement :
After JEE Mains, some students got admission into an engineering college. Now there is a class consisting of such n students, and the HOD came to say it is time to select the class monitor. But He never gets all of them at one time. So he brought a register, every time he gets someone with less rank than the previous time he cut the name and wrote the name of the student and the rank.
For a given number of ranks he gets each time, you have to predict how many names are cut in the list.
Constraints:
Number of Visiting<=10^9
ranks <=10000
Input Format:
Number of Visiting N in their first line
N space separated ranks the HOD gets each time
Output Format:
Number of ranks cut in the list
Sample Input:
6
4 3 7 2 6 1
Sample Output:
3
#include <bits/stdc++.h> using namespace std; int main() { int n, p, m = INT_MAX, ans = 0; cin >> n; vector < int > a(n); for (int i = 0; i < n; i++) { cin >> p; if (p < m) { m = p; ans++; } } cout << ans - 1; }
import java.util.Scanner; public class Main { public static void main(String[] args) { int n, p, ans = 0, m = Integer.MAX_VALUE; Scanner sc = new Scanner(System.in); n = sc.nextInt(); for (int i = 0; i < n; i++) { p = sc.nextInt(); if (p < m) { m = p; ans++; } } System.out.print(ans - 1); } }
n = int(input()) a = list(map(int, input().split())) m = a[0] ans = 0 for i in range(1, n): if a[i] < m: m = a[i] ans += 1 print(ans)
Question 6 : 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 7: HR issues
Problem statement :
Shovon is an HR in a renowned company and he is assigning people to work. Now he is assigning people work in a fashion where if he assigns some work a work of cost 2, the next person will be strictly getting a job with cost equal or more than 2. Given that Shovon’s company has infinite work and a number of employees, how many distributions can be possible. The cost of jobs can go 0 to 9.
Function Description:
Complete the special_numbers function in the editor below. It has the following parameter(s):
Parameters:
Name | Type | Description |
N | Integer | The number of depts. |
arr[ ] | Integer array | The number of employees in each dept.. |
Return: The function must return an INTEGER denoting the sum of answers for all distinct distributions.
Constraints:
- 1 <= n <= 100
- 1 <= arr[i] <= 200
Sample Cases:
- Sample Input 1
2
4
1 - Sample Output 1
725 - Description
The ans if m = 1 is 10, which is all numbers from 0 to 9
The ans for m = 2 is 55
The answer for m = 3 is 220
The answer for m = 4 is 715
So fun(4) + fun(1) = 725
#include<bits/stdc++.h> using namespace std; int func(int s,int p,int n) { if(p==n-1) return 1; int ans=0; for(int i=s;i<=9;i++) ans+=func(i,p+1,n); return ans; } int main() { int n,a, ans=0; cin>>n; vector v(n); for(int i=0;i<n;i++) { cin>>a; for(int i=0;i<=9;i++) ans+=func(i,0,a); } cout<<ans; }
n=int(input()) a1=[] for i in range(n): a1.append(int(input())) dp=[0]*201 dp[1]=10 dp[2]=55 a=[1]*10 i=3 while i<201: s=0 for i1 in range(10): s+=a[i1] a[i1]=s dp[i]+=(s*(10-i1)) dp[i]=dp[i]%((10**9)+7) i+=1 s1=0 for i in a1: s1+=dp[i] s1=s1%((10**9)+7) print(s1)
import java.util.*; class Main { static int func(int s,int p,int n) { if(p==n-1) return 1; int ans=0; for(int i=s;i<=9;i++) ans += func(i,p+1,n); return ans; } public static void main (String[]args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt (); int ans=0; for(int i=0; i<n; i++){ int a = sc.nextInt (); for(int j=0; j <=9; j++) ans+=func(j,0,a); } System.out.println (ans); } }
Question 8 : 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 9 :
How will we represent a binary tree? We can use a bracket structure for all of the edges, like (Parentnode , Childnode). Now if we use a node in child node more than once, the tree can not be valid. Same for the parent node, a node can not be taken more than twice in a graph as a parent node.
Suppose we see this one graph
(P,Q)(P,R)(Q,T)(R,W)(U,V)(Q,S)(R,U)(U,Z)(S,I)(W,Y)
A tree with those edges may be illustrated in many ways.Here are two:
P P
/ \ / \
Q R Q R
/ \ / \ / \ / \
S T U W S T U W
\ / \ \ / / \ \
I V Z Y I Z V Y
The following is a recursive definition for the S-expression of a tree.
S-exp(node)=(node->val(S-exp(node->first_child))(S-exp(node->second_child))),if node
!NULL=””,node= =NULL
Where first_child->valval(first_child->val is lexicographically than second_child->val)
This tree can be represented in S-expression in multiple ways.The lexicographically smallest way of expressing it as follows:
P(Q(S(I))(T))(R(U(V)(Z))(W(Y))))
Translate the node-pair representation into its lexicographically smallest S-expression or report any errors that do not conform to the definition of the binary tree.
The List of errors with their codes is as follows:
Error Reason
Code Stopped1 More than 2 children
Code Stopped2 Duplicate Edges
Code Stopped3 Cycle Present(node is direct descendant of more than one node)
Code Stopped4 Multiple Roots
Code Stopped5 Any other error
Constraints:
- All node names are single characters in the range ascii[A-Z].
- The maximum node count is 26.
- There is no specific order to the input (parent,child) pairs.
>Input Format for Custom Testing
>Sample Case 0
Sample Input 0
- (B,D) (D,E) (A,B) (C,F) (E,G) (A,C)
Sample output 0
- (A(B(D(E(G))))(C(F)))
Explanation 0
A representation of tree is as follows:
A
/ \
B C
/ \
D F
/
E
/
G
>Sample Case 1
Input:
- (C,E)(D,F)(A,B)(A,C)(B,K)
Output:
- A(B(K))(C(E)))D(F))
#include<bits/stdc++.h> using namespace std; string s, ans = ""; unordered_map < char, int > root, child, flag; //rootOf,childOf map < pair < char, char > , int > duplicateedgecheck; //Duplicate edge check unordered_map < char, char > par, ch[2], monitor; char find(char c) { if (monitor[c]) return monitor[c]; if (root[c] == 0) return monitor[c] = c; return monitor[c] = find(par[c]); } void makeans(char c) { if (flag[c] == 0) { ans += c; flag[c]++; if (child[c] == 2) { ans += '('; makeans(min(ch[0][c], ch[1][c])); ans += '('; makeans(max(ch[0][c], ch[1][c])); } else for (int i = 0; i < child[c]; i++) { ans += '('; makeans(ch[i][c]); } ans += ')'; } } int main() { getline(cin, s); for (int i = 0; i < 26; i++) { root['A' + i] = -5; } for (int i = 0; i < s.length(); i++) if (s[i] == '(') { child[s[i + 1]]++; root[s[i + 3]] = root[s[i + 3]] == -5 ? 1 : root[s[i + 3]]++; duplicateedgecheck[{ min(s[i + 1], s[i + 3]), max(s[i + 1], s[i + 3]) }]++; root[s[i + 1]] == -5 ? root[s[i + 1]] = 0 : 1; ch[0][s[i + 1]] == '\0' ? ch[0][s[i + 1]] = s[i + 3] : ch[1][s[i + 1]] = s[i + 3]; par[s[i + 3]] = s[i + 1]; if (child[s[i + 1]] > 2) { cout << "Code Stopped1"; return 0; } if (duplicateedgecheck[{ min(s[i + 1], s[i + 3]), max(s[i + 1], s[i + 3]) }] > 1) { cout << "Code Stopped2"; return 0; } if (find(s[i + 1]) == find(s[i + 3]) && s[i + 1] != par[s[i + 3]]) { cout << "Code Stopped3"; return 0; } if (root[s[i + 3]] > 1) { cout << "Code Stopped4"; return 0; } if (s[i + 4] != ')' || s[i + 2] != ',') { cout << "Code Stopped5"; return 0; } //i+=5; } for (int i = 0; i < 26; i++) { if (root['A' + i] == 0) makeans('A' + i); } cout << ans; }
Question 10: Consecutive Prime Sum
Problem Description
Question – : Some prime numbers can be expressed as a sum of other consecutive prime numbers.
- For example
- 5 = 2 + 3,
- 17 = 2 + 3 + 5 + 7,
- 41 = 2 + 3 + 5 + 7 + 11 + 13.
Your task is to find out how many prime numbers which satisfy this property are present in the range 3 to N subject to a constraint that summation should always start with number 2.
Write code to find out the number of prime numbers that satisfy the above-mentioned property in a given range.
Input Format: First line contains a number N
Output Format: Print the total number of all such prime numbers which are less than or equal to N.
Constraints: 2<N<=12,000,000,000
#include int prime(int b); int main() { int i,j,n,cnt,a[25],c,sum=0,count=0,k=0; printf("Enter a number : "); scanf("%d",&n); for(i=2;i<=n;i++) { cnt=1; for(j=2;j<=n/2;j++) { if(i%j==0) cnt=0; } if(cnt==1) { a[k]=i; k++; } } for(i=0;i<k;i++) { sum=sum+a[i]; c= prime(sum); if(c==1) count++; } printf(" %d",count); return 0; } int prime(int b) { int j,cnt; cnt=1; for(j=2;j<=b/2;j++) { if(b%j==0) cnt=0; } if(cnt==0) return 1; else return 0; }
Output Enter a number : 43 4
#include<bits/stdc++.h> using namespace std; int prime(int b) { int j,cnt; cnt=1; for(j=2;j<=b/2;j++) { if(b%j==0) cnt=0; } if(cnt==0) return 1; else return 0; } int main() { int i,j,n,cnt,a[25],c,sum=0,count=0,k=0; cout<<"Enter a number : "; cin>>n; for(i=2;i<=n;i++) { cnt=1; for(j=2;j<=n/2;j++) { if(i%j==0) cnt=0; } if(cnt==1) { a[k]=i; k++; } } for(i=0;i<k;i++) { sum=sum+a[i]; c= prime(sum); if(c==1) count++; } cout<<count; return 0; }
Output Enter a number : 5 1
import java.util.Scanner; class Main { static int prime(int b) { int j,cnt; cnt=1; for (j = 2; j <= b/2; j++) { if(b%j==0) cnt=0; } if(cnt==0) return 1; else return 0; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i,j,n=0,cnt,c=0,sum=0,count=0,k=0; Main t = new Main(); int[] a = new int[25]; System.out.println("Enter no"); n = sc.nextInt(); for (i = 2; i <=n ; i++) { cnt=1; for (j = 2; j <= n/2; j++) { if(i%j==0) cnt=0; } if(cnt==1) { a[k]=i; k++; } } for (i = 0; i < k; i++) { sum=sum+a[i]; c=t.prime(sum); if(c==1) count++; } System.out.println(count); } }
Output 43 4
num = int(input()) arr = [] sum = 0 count = 0 if num > 1: for i in range(2, num + 2): for j in range(2, i): if i % j == 0: break else: arr.append(i) def is_prime(sum): for i in range(2, (sum // 2) +2): if sum % i == 0: return False else: return True for i in range(0, len(arr)): sum = sum + arr[i] if sum <= num: if is_prime(sum): count = count + 1 print(count)
Output 20 2
FAQs related to Kotak Mahindra SDE
Question 1: What is the role offered in Kotak Mahindra Bank?
The roles offered in this hiring of Kotak Mahindra Bank is for Software Development Engineer , your role would initially involve extensive training for imparting the required level of skills, for effectively carrying out the official responsibilities assigned to you.
Question 2: What is Kotak Mahindra Bank Recruitment Process?
The Online Selection Process consist of
- 3 Written test of DSA
- Technical + Hiring Manager Round interviews
Question 3:What is online assessment test in Kotak Mahindra Bank?
The Online Assessment consist of
- DSA Coding Question
- Computer Fundamental Questions
- Question Based on Projects
Question 4: What should be need to prepare for successfully cleared the test?
For successfully clearing the tests, you should prepare DSA completely with proper practice along with that you should also prepare computer fundamental questions.
Question 5: What is the Salary offered for the roles?
The Salary Package for Kotak Mahindra Bank Software Development engineer is in between 10 – 12 lpa.
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