# Persistent Coding Test Questions 2021

Here you will get all the detailed information related to Persistent Coding Test Questions 2021.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 Section | Coding Assessmneet |

Number of Questions | 2 |

Total Time Limit | 20 min |

Difficulty Level | High |

## Persistent Coding Test Questions Curriculum 2020-21

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:-**20 min**Difficulty Level-**High

**Questions in 2020-2021 With Solutions:-**

**Persistent Coding Test Question 1**

Many simple encoding techniques has been devised over a period of time. A common method having to do with the computer is the ASCII character set used to display characters on the screen. Each character is been given a numeric value which can be interpreted by the computer.

In this challenge, you will be given a string to decode. An example of the encoded string follows. The table shows the conversion from the string PrepInsta to the ASCII string 801141011127311011511697;

Character | P | r | e | p | I | n | s | t | a |
---|---|---|---|---|---|---|---|---|---|

ASCII value | 80 | 114 | 101 | 112 | 73 | 110 | 115 | 116 | 97 |

We then reverse the ASCII string to get the encoded string 796115110113721110141108

To decode the string first reverse the string of digits, then successfully pick valid values from the string and convert them to their ASCII equivalents. Some of the values will have two digits, and others three. Use the range of valid values while decoding the string of digits.

For reference, the character in s correspond to the following ASCII values

- The value range from A to Z is 65 to 90
- The value range from a to z is 97 to 122
- The value of space character is 32

**Function Description**

Write a function decode. The function must return the original decoded string.

decode() has the following parameters:

- encoded: an encoded string

**Constraints**

- 1 <= |s| <= 105
- s[i] ∈ {ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz}

**Sample Input 0**

23511011501782351112179911801562340161171141148

**Sample Output 0**

Truth always wins

**Explanation 0**

We reverse encoded to get 8411411711610432651081197121115328710511011532. We then replace each ASCII Value with its corresponding character:

num = input() num = num[::-1] Final_string = '' number = '' for i in range(len(num)): number = number + num[i] if (int(number) >= 65 and int(number) <= 90) or (int(number) >= 97 and int(number) <= 122) or (int(number) == 32): character = chr(int(number)) Final_string+=character number = '' print(Final_string)

Output: 23511011501782351112179911801562340161171141148 Truth Always Wins

**Persistent Coding Test Question 2**

Create the username portal of a registration system that requires all username are unique. If a new user requests a name that is already registered, an integer should be added to the end of the username to make it unique. The number begins with 1 and is incremented by 1 for each new instance per username.

As an example if username requests were for {bob, alice, bob, alice,bob, alice}, the system should assign usernames {bob, alice,bob1, alice1,bob2, alice2}.

Given a list of usernames requests in the order given, process all requests and return an array of usernames as assigned by the function

**Function Description**

Write a function usernameSystem, that must return an array of usernames in the order assigned

usernameSystem hgas the following parameters

- u{u(0),u(1)……u(n-1)}, an array of username strings in the order requested

**Constraints**

- 1<= n <= 104
- 1 <= u[i] <= 20
- U[i] contains only lowercase ascii characters in the range [a-z].

**Example:**

**Input**

alex

xylos

alex

alan**Output**

alex

xylos

alex1

alan

import collections,re class Personname: def clean(self,user_names): count_map = collections.defaultdict(int) for i in range(len(user_names)): name = user_names[i] name = re.sub(r'[0-9]+$', '',name) count = count_map[name] if count != 0: user_names[i] = name + str(count) count_map[name] += 1 u = Personname() arr =[ 'bob', 'alice', 'bob', 'alice','bob', 'alice'] u.clean(arr) print(arr)

Output: ['bob', 'alice', 'bob1', 'alice1', 'bob2', 'alice2']

**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:

- An array of integers,arr,denoting the elements in the array.
- 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

**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

## 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

Login/Signup to comment