# PayPal Coding Questions and Answers

## PayPal Coding Questions with Solutions

In this page, you will find out Paypal Coding Questions and Answers asked in Online Assessment and Technical Interview involved in the Hiring Process of the Company.

Go through this page to get more details like Job Profile, CTC Offered, Steps involved in the recruitment process, etc. of the company.

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

0

#### Explanation :

The substring from index =1 to index=3 is “*|*” . there is no consecutive pair of bars in this string.

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

### Question 2: Queries for Count

The task is to determine the number of elements within a specified range in an unsorted array. Given an array of size n, the goal is to count the elements that fall between two given values, i and j, inclusively.
Examples:

Input:
Array: [1, 3, 3, 9, 10, 4]
Range 1: i = 1, j = 4
Range 2: i = 9, j = 12

Output:
For Range 1: 4
For Range 2: 2

Explanation:
In the first query, the numbers within the range 1 to 4 are 1, 3, 3, and 4.
In the second query, the numbers within the range 9 to 12 are 9 and 10.

### Question 3: k th largest factor of N

Problem Description:
A positive integer d is said to be a factor of another positive integer N if when N is divided by d, the remainder obtained is zero. For example, for number 12, there are 6 factors 1, 2, 3, 4, 6, 12. Every positive integer k has at least two factors, 1 and the number k itself. Given two positive integers N and k, write a program to print the kth largest factor of N.

Input Format: The input is a comma-separated list of positive integer pairs (N, k).

Output Format: The kth highest factor of N. If N does not have k factors, the output should be 1.

Constraints:

• 1<N<10000000000
• 1<k<600.

You can assume that N will have no prime factors which are larger than 13.

Example 1

• Input: 12,3
• Output: 4

Explanation: N is 12, k is 3. The factors of 12 are (1,2,3,4,6,12). The highest factor is 12 and the third largest factor is 4. The output must be 4.

Example 2

• Input: 30,9
• Output: 1

Explanation: N is 30, k is 9. The factors of 30 are (1,2,3,5,6,10,15,30). There are only 8 factors. As k is more than the number of factors, the output is 1.

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

### Question 5: Spiral Matrix

Problem Statement :

You will be given a 2d matrix. Write the code to traverse the matrix in a spiral format. Check the input and output for better understanding.

Sample Input :
Input :
5 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20

Output :

1 2 3  4 5 6 7 8 9 10 11 12 13 14  15 16 17 18 19 20

### Question 6: Network Stream

Problem Statement :

A stream of n data packets arrives at a server. This server can only process packets that are exactly 2^n units long for some non-negative integer value of n (0<=n).
All packets are repackaged in order to the 1 largest possible value of 2^n units. The remaining portion of the packet is added to the next arriving packet before it is repackaged. Find the size of the largest repackaged packet in the given stream.

Example arriving Packets = [12, 25, 10, 7, 8]
The first packet has 12 units. The maximum value of 2^n that can be made has 2^n = 2^3 = 8 units because the next size up is 2^n = 2^4 = 16 (16 is greater than 12).

12 – 8 = 4 units are added to the next packet. There are 4 + 25 = 29 units to repackage, 2^n = 2^4 = 16 is the new size leaving 9 units (29-16 = 9)

Next packet is 9 + 10 = 29 unists & the maximum units(in 2^n) is 16 leaving 3 units.
3 + 7 = 10 , the max units is 8 Leaving 2 units, and so on.
The maximum repackaged size is 16 units.

Returns:
Long : the size of the largest packet that is streamed

Constraints :
1<=n<=10^5
1<=arriving Packets[i] size<=10^9

Sample case 0 :

Sample input 0:
5 → number of packets=5
13→ size of packets=[13,25,12,2,8]
25
10
2
8
Sample output 0:
16

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

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

### Question 9: 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

### Question 10 :

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:

1. All node names are single characters in the range ascii[A-Z].
2. The maximum node count is 26.
3. 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))

## FAQs on PayPal Games Coding Questions

##### Question 1: How do I prepare for a PayPal technical interview?

Applicants must have Good Command in Advanced DSA and Core Computer Science Engineering concepts to pass the Technical Interview of PayPal.

##### Question 2: What is the salary of PayPal Sde1?
PayPal SDE 1 salary in India ranges between ₹ 12.0 Lakhs to ₹ 16 Lakhs for less than 1 year of experience.
##### Question 3: How many rounds are there in PayPal Recruitment Process?

There are 3 Rounds conducted for PayPal Recruitment Process:

1. Online Aptitude + Technical Assessment
2. Technical Interview
3. HR Interview