Problem 1: Prime Number Verification

You are required to implement a function that checks whether a given positive integer ‘N’ is a prime number or not. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself (e.g., 2, 3, 17, etc.).

Input Format:

A single positive integer ‘N’ is given as input.

Output Format:

If ‘N’ is a prime number, return “PRIME”.

Otherwise, return “NOT PRIME”.

Note:

The implementation of the function is required; printing the result is not necessary.

Constraints:

2 <= N <= 10^7

Problem Approach:

Accept ‘num’ as input.

Initialize ‘temp’ to 0.

Iterate a “for” loop from 2 to num/2.

If num is divisible by the loop iterator, increment ‘temp’.

If temp is equal to 0, return “PRIME”; otherwise, return “NOT PRIME”.

Problem 2: Split Array into Fibonacci Sequence

You are given a string ‘S’ consisting of digits. Your task is to split ‘S’ into a Fibonacci-like sequence [F[0], F[1], …, F[n]] such that:

0 <= F[i] <= 2^31 – 1

n >= 3

F[i] + F[i+1] = F[i+2] for all 0 <= i < n – 2

Also, each piece of the split sequence must not have extra leading zeroes, except if the piece is the number 0 itself. Return any valid Fibonacci-like sequence split from ‘S’, or an empty list if it cannot be done.

Input Format:

The first line contains an integer ‘T’, denoting the number of test cases.

For each test case, a string ‘S’ is given as input.

Output Format:

For each test case, return the first Fibonacci-like sequence list that can be formed by splitting ‘S’, or return an empty list if not possible.

Note:

The implementation of the function is required; printing the result is not necessary.

Constraints:

1 <= T <= 100

1 <= |S| <= 200

Problem Approach:

Start by declaring variables: ‘I’, ‘a’, ‘b’, and ‘show’.

Initialize ‘a’ and ‘b’ as 0 and 1 respectively, and ‘show’ as 0.

Accept the number of terms of the Fibonacci series to be printed.

Print the first two terms of the series.

Use a loop for the following steps:

Calculate ‘show’ as ‘a’ + ‘b’

Update ‘a’ to ‘b’

Update ‘b’ to ‘show’

Increment ‘I’ by 1

Print the value of ‘show’

End the process.

Kempston Interview Experience SDE-1

Similar Reads

Round – 01

Level: Easy...

Problem 1: Prime Number Verification

You are required to implement a function that checks whether a given positive integer ‘N’ is a prime number or not. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself (e.g., 2, 3, 17, etc.)....

Round – 02

Level: Easy...

Round – 03

Level: Easy...