Open In App

Kempston Interview Experience SDE-1

Last Updated : 18 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Round – 01

Level: Easy

Time Limit: 60 minutes

Problem Set: 2 Problems

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.

Round – 02

Level: Easy

Time Limit: 60 minutes

Problem Set: 2 Problems

Problem 1: Factorial Calculation

You are given an integer ‘N’. Calculate and print the factorial of ‘N’, which is the product of all numbers from 1 to ‘N’.

Input Format:

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

For each test case, a single integer ‘N’ is given.

Output Format:

For each test case, print the value of factorial of ‘N’.

Constraints:

1 <= T <= 10

1 <= N <= 100

Problem Approach:

Accept the number of test cases ‘T’.

For each test case:

Accept the integer ‘N’.

Calculate and print the factorial of ‘N’.

Problem 2: Median of Two Sorted Arrays

Given two sorted arrays ‘a’ and ‘b’ of sizes ‘n’ and ‘m’ respectively, find the median of the combined array. The median is the middle value of a sorted list of numbers. If the length of the list is even, the median is the average of the two middle elements.

Input Format:

The first line contains two space-separated integers ‘n’ and ‘m’, representing the sizes of the two arrays.

The second line contains ‘n’ space-separated integers representing the elements of the first array.

The third line contains ‘m’ space-separated integers representing the elements of the second array.

Output Format:

Print a single value denoting the median of the combined array.

Problem Approach:

Accept ‘n’ and ‘m’ representing the sizes of arrays ‘a’ and ‘b’.

Accept the elements of arrays ‘a’ and ‘b’.

Combine ‘a’ and ‘b’.

Calculate and print the median of the combined array.

Round – 03

Level: Easy

Time Limit: 60 minutes

Problem Set: 1 Problem

Problem: Generate Permutations

Duration: 60 minutes

Given an input string ‘S’, generate and return all possible permutations of the characters in ‘S’. Note that the order of permutations does not matter, and there may be repeated characters in ‘S’.

Input Format:

The first and only line of input contains a string ‘S’ consisting of lowercase alphabets.

Output Format:

Print all permutations of the characters in ‘S’ in separate lines.

Constraints:

0 <= |S| <= 8

Problem Approach:

Accept the input string ‘S’.

Generate and print all possible permutations of the characters in ‘S’.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads