Persistent Coding Test Questions 2022

Here you will get all the detailed information related to Persistent Coding Test Questions 2022. Below you will get questions for practice so that you can score good marks in Persistent Coding Test Questions.

The difficulty level of the Persistent Coding Test Questions is high.

Name of the SectionCoding Assessment
Number of Questions2
Total Time Limit40 min
Difficulty LevelHigh

Persistent Coding Test Questions Curriculum 2022

In Persistent Coding there will be 2 Coding Questions that you have to solve in C Language.You can write code in only one language.

  • C language

The difficulty level of the questions will be high. You have to solve at least 1 and half question to get select for the next round. So you have to practice a lot so that you can solve questions of Persistent coding test.

Detailed analysis of Persistent Coding Test Questions and Answers:

  • Number of Questions:- 2
  • Time Limit:- 40 min
  • Difficulty Level- High

Persistent Coding Questions in 2022 With Solutions:-

Persistent Coding Test Question 1

Sajith loves numbers and coding. His dad gives a task to write a code to find the nth largest number in an array.

Input 

  • The inputs have : First the count of integers and the second n value
  • The second line of the input has the list of integers that he needs to do the operations upon.

Output

  • You have to print the integer representing the nth largest out of the numbers given by his father

 

Constraints

  • 0 < value n <=  count of integers <= 10^6
  • -10^6 <= each integer <= 10^6
  • 0 <= i < count of integers

 

Example

Input

5  3
11 -1 – 4 12 -6

Output 

-1

Explanation :

-1 is 3rd largest

 

#include <stdio.h>

/* Function to print array */
void display (int arr[], int n)
{
  printf ("%d ", arr[n]);
}

// Main function to run the program
int main ()
{
  int count, n, i;
  scanf ("%d %d", &count, &n);

  printf ("count: %d, n: %d\n", count, n);

  int array[count];

  for (i = 0; i < count; i++)
    scanf ("%d", &array[i]);

  printf ("Before bubble sort: \n");
  display (array, count);

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

      // Since, after each iteration righmost i elements are sorted
      for (j = 0; j < count - i - 1; j++) if (array[j] > array[j + 1])
	    {
	        temp = array[j];	// swap the element
	        array[j] = array[j + 1];
	        array[j + 1] = temp;
	    }
    }
  printf ("After bubble sort: \n");
  display (array, count - n);

  return 0;
}
import java. util. Arrays;
import java.util.*;

public class Main
{
    public static void main(String[] args) {
        int n,k;
        Scanner sc= new Scanner(System.in);
        n=sc.nextInt();
        k=sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; i++)
        {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[n-k]);
    }
}

n,k=map(int,input().split())
print(sorted(list(map(int,input().split())))[-k])

Persistent Coding Test Question 2

Flipkart has been infected with a virus, the virus works this way: Each user that has been infected with the virus is traced by a special algorithm and a hint that the virus gives. The virus leaves a hint number N.

Flipkart is able to identify the user ID of the virus by this N number as the user ID works as a series : Each number in the series is the sum of the last three numbers in the series. The first three numbers in the series are 0, 0, 1 always.

Write a program to identify the user ID infect based on N value checked from the logs of the system

Input

  • The input contains the N value left by the virus and found by engineers in the logs of the system

Output

  • Print the userID of the infect user.

 

Example

Input

11

Output 

81

 

Example

Input

16

Output 

1705

#include <stdio.h>
int main()
{
    int a = 0, b = 0, c = 1;
    int num, i, temp, e1, e2;
    scanf("%d",&num);
    if(num==1)
    {
        printf("0");
    }
    else if(num==2)
    {
        printf("0");
    }
    else if(num==3)
    {
        printf("1");
    }
    else
    {
        for(i=1; i<num-2; i++)
        {
            temp = a + b + c;
            e1 = c;                
            e2 = b;
            c = temp;                  
            b = e1;                 
            a = e2;                 
        }
        printf("%d",temp);
    }
    return 0;
}
N = int(input())
N1, N2, N3 = 0, 0, 1
user_id = 0
N4 = 1

if N <= 0:
   print("Please enter a positive integer")
elif N == 1:
   print(N1)
elif N == 2:
    print(N2)
elif N == 3:
    print(N3)
else:
    for i in range(N-3):
       N4 = N1 + N2 + N3
       N1 = N2  #updating values
       N2 = N3
       N3 = N4
    print(N4)

Persistent Coding Question 3

Given an unsorted array of n elements, find if the element k is present in the array or not. Complete the findNumber function in the editor below.

It has 2 parameters:

  1. An array of integers,arr,denoting the elements in the array.
  2. An integer,k,denoting the element to be searched in the array.

The function must return a string “YES” or “NO” denoting if the element is present in the array or not.

Input Format

  • The first line contains an integers n,denoting the number of elements in the array arr.
  • Each line i of the n subsequent lines (where 0<=i<=n) contains an integer describing arri.
  • The next line contains an integer,k,the elements that needs to be searched.

Constraints

  • 1 <= n <= 105
  • 1 <= arr[i]<= 109

Output Format

The function must return a string “YES” or “NO” denoting if the element is present in the array or not.This is printed to stdout by locked stub code in the editor.

Sample Input 0

5
1
2
3
4
5
1

Sample Output 0

YES

Explanation 0

Given the array =[1,2,3,4,5],we want to find the element 1 if it is present or not. We can find the element 1 at index = 0.Therefore we print “YES”.

Sample Input 1

3
2
3
1
5

Sample Output 1

NO

Explanation 1

Given the array[2,3,1] and k = 5. There is no element 5 in the array and therefore we print “NO”.

n = int(input())
arr = []
for i in range(n):
    name = int(input())
    arr.append(name)
k = int(input())
if k in arr:
    print('YES')
else:
    print('NO')
Output:
5
1
2
3
4
5
1
YES
#include <iostream>
using namespace std;

void findNumber(int arr[],int k,int size){
    int flag;
    for(int i=0;i<size;i++){
        if(arr[i]==k){
           flag = 1;
        }
    }
    
    if(flag ==1)
    cout<<"Yes";

    else
    cout<<"No";
}
int main()
{
    int arr[]= {1,5,7,8,9,10};
    int n = sizeof(arr) / sizeof(arr[0]);
    int k = 10;

    findNumber(arr,k,n);
    return 0;
}
#include <stdio.h>

void findNumber(int arr[],int k,int size){
    int flag;
    for(int i=0;i<size;i++){
        if(arr[i]==k){
           flag = 1;
        }
    }
    
    if(flag ==1)
    printf("Yes");
    
    else
    printf("No");
}
int main()
{
    int arr[]= {1,5,7,8,9,10};
    int n = sizeof(arr) / sizeof(arr[0]);
    int k = 10;
    findNumber(arr,k,n);
    return 0;
}

Persistent Coding Question 4

Sum is given a rectangular paper having dimension h x w, where h is the height and w is the width. Sam wants to fold the paper so its dimension are h1 x w1 in the minimum number of moves. The paper can only be folded parallel to its edges, and after folding the dimension should be integers.

For example, given h =8 and w =4, fold the paper until it is h1,w1 =6,1. Find fold along the long edge 6 units from a side, resulting in a paper that is 6 x 4. Next, fold along the width 2 units from the 4 unit edge to have 6 x 2. Fold along the center of the 2 units edge to achieve a 6 x 111 page in three folds.

Function Description

Write a function minMoves, which will return an integer value that denotes the minimum number of moves in which the task can be achieved

minMoves has the following parameter:

  • h: an integer that denotes the initial height
  • w: an integer that denotes the initial width
  • h1: an integer that denotes the final height
  • w1: an integer that denotes the initial width

Sample Input 0

2
3
2
2

Sample Output 0

1

Explanation

The initial dimension of the paper is 2 x 3. This should be connected to 2 x 2. Fold along a line 1 unit in from the edge of the 7 unit side.

Sample Input 1

6
3
3
1

Sample Output 1

3

Explanation

Initial dimension of the paper are 6 x 3. This should be connected to 3 x 3. This can be done in the following way. There can be many other ways to solve, this is one of the ways.

6 x 3 -> 3 x 3 -> 3 x 2 -> 3 x 1.

h = float(input())
w = float(input())
h1 = float(input())
w1 = float(input())
count = 0
while h != h1:
    if h1 <= h/2: count+=1 h = h/2 elif h1 > h/2:
        count+=1
        h = abs(h-(h-h1))
while w != w1:
    if w1 <= w/2: count+=1 w = w/2 elif w1 > w/2:
        count+=1
        w = abs(w-(w-w1))
print(count)
Output:
6
3
3
1
3
#include<iostream.h>
using namespace std;

int main() {
   float h=4, w=8;
int h1=6, w1=1;
   int count = 0;    while (h != h1 || w != w1) {        if (h != h1) {            if (h1 >= h / 2) {                h = h1;            } else {                h = h / 2;            }            count++;        }        if (w != w1) {            if (w1 >= w / 2) {                w = w1;            } else {                w = w / 2;            }            count++;        }    }    cout << count << endl;    return 0; }
#include<stdio.h>

int main() {
    float h=4, w=8;
    int h1=1, w1=6;
    
    int count = 0;
    while (h != h1 || w != w1) {
        if (h != h1) {
            if (h1 >= h / 2) {
                h = h1;
            } else {
                h = h / 2;
            }
            count++;
        }
        if (w != w1) {
            if (w1 >= w / 2) {
                w = w1;
            } else {
                w = w / 2;
            }
            count++;
        }
    }
    printf("%d", count );
    return 0;
}

Frequently Asked Questions (FAQs)

 What is the difficulty level of this coding round?

The difficulty level of this section is higher than the rest of the sections

Which programming language is recommended for coding round?

 You can write code in only one language.

  • C language

2 comments on “Persistent Coding Test Questions 2022”


  • Piyush

    Why the code is written in Python ?.
    The exam consists of only.
    These are easy with python but not c indeed.