Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views22 pages

Fisat 2025-1

Uploaded by

noorasherief
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views22 pages

Fisat 2025-1

Uploaded by

noorasherief
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Basic Level Question

#1 Leap Year

An extra day is added to the calendar almost every four years as February 29, and the day is called a leap day.
It corrects the calendar for the fact that our planet takes approximately 365. 25 days to orbit the sun. A leap year
contains a leap day.

In the Gregorian calendar, three conditions are used to identify leap years:

● The year can be evenly divided by 4, is a leap year, unless:


● The year can be evenly divided by 100, it is NOT a leap year, unless:
● The year is also evenly divisible by 400. Then it is a leap year.
● This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900,
2100, 2200, 2300 and 2500 are NOT leap years.

Platform
#2 Second Largest

Given the participants' score sheet for your University Sports Day, you are required to find the runner-up
score. You are given n scores. Store them in a list and find the score of the runner-up.

Constraints

● Cant use any builtin functions


● Only use 1 for loop

Platform

example

23685

288555
#4 Valid Parentheses

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
● Open brackets must be closed by the same type of brackets.
● Open brackets must be closed in the correct order.
● Every close bracket has a corresponding open bracket of the same type.

Example 1
Input : {[]{}()}
Output : Valid

Example 2
Input : ()}{]]
Output : Invalid
#5 String Compression

Given a string, you need to compress it by replacing consecutive identical characters with the character
followed by the count of occurrences. If a character appears only once consecutively, it should be included as
is (without the count).

Example 1

Input: aaaabbbcccdeee

Output: a4b3c3de3

Example 2

Input: aaaabbbcccdeeeaa

Output: a4b3c3de3a2
#6 Apple and Orange

Sam's house has an apple tree and an orange tree that yield an abundance of fruit. Using the
information given below, determine the number of apples and oranges that land on Sam's house.

Detailed Question in Hackerrank Question


#7 Kangaroo Jump

You are choreographing a circus show with various animals. For one act, you are given two kangaroos on
a number line ready to jump in the positive direction (i.e, toward positive infinity).

The first kangaroo starts at location and moves at a rate of meters per jump.
The second kangaroo starts at location and moves at a rate of meters per jump.
You have to figure out a way to get both kangaroos at the same location at the same time as part of the
show. If it is possible, return YES, otherwise return NO.

Detailed Question in Hackerrank Question


#8 Who Can See the Board

In a classroom, N students are standing in a straight line, one behind the other, and facing the front of the classroom where
a board is placed. The heights of the N students are given in an array heights[], where heights[i] represents the
height of the i-th student from the front of the class.

A student can see the board if and only if no student standing in front of them is taller or of equal height. For example, if a
student at position i is taller than all the students before them (positions 0 to i-1), they can see the board.
Your task is to write a program that determines the number of students who can see the board.

Input:

● An integer N representing the number of students.


● An array heights[] of size N, where each element is a positive integer representing the height of the corresponding student.

Output:

● An integer representing the number of students who can see the board.

Input:
N=8
heights[] = [150, 160, 155, 158, 170, 180, 165, 175]
Output: 4
#9 Bird Count

Given an array of bird sightings where every element represents a bird type id, determine the id of the most
frequently sighted type. If more than 1 type has been spotted that maximum amount, return the smallest of their
ids.

Example

arr=[1,1,2,3,3]

There are two each of types and , and one sighting of type . Pick the lower of the two types seen twice: type .

Reference
# 10 Count Guest

A party has been organised on cruise. The party is organised for a limited time(T). The number of guests
entering (E[i]) and leaving (L[i]) the party at every hour is represented as elements of the array. The task
is to find the maximum number of guests present on the cruise at any given instance within T hours.

Example 1:
Input :

5 -> Value of T
[7,0,5,1,3] -> E[], Element of E[0] to E[N-1], where input each element is separated by new line
[1,2,1,3,4] -> L[], Element of L[0] to L[N-1], while input each element is separate by new line.
Output :
8 -> Maximum number of guests on cruise at an instance.
# 11 Packing Candies

Krishna loves candies a lot, so whenever he gets them, he stores them so that he can eat them later whenever
he wants to. He has recently received N boxes of candies each containing Ci candies where Ci represents the
total number of candies in the ith box. Krishna wants to store them in a single box. The only constraint is that he
can choose any two boxes and store their joint contents in an empty box only. Assume that there are an infinite
number of empty boxes available.At a time he can pick up any two boxes for transferring and if both the boxes
contain X and Y number of candies respectively, then it takes him exactly X+Y seconds of time. As he is too
eager to collect all of them he has approached you to tell him the minimum time in which all the candies can be
collected.
Input Format:
The first line of input is the number of test case T
Each test case is comprised of two inputs
The first input of a test case is the number of boxes N
The second input is N integers delimited by whitespace denoting the number of candies in each box
Output Format: Print minimum time required, in seconds, for each of the test cases.
# 11 Packing Candies

Input : Input :
1 1
4 5
4231 52734
Output : Output :
19 47

Explanation :
4 boxes, each containing 1, 2, 3 and 4 candies respectively.Adding 1 + 2 in a new box takes 3
seconds.Adding 3 + 3 in a new box takes 6 seconds.Adding 4 + 6 in a new box takes 10 seconds.Hence
total time taken is 19 seconds. There could be other combinations also, but overall time does not go
below 19 seconds.
# 13 Chocolate Factory

A chocolate factory is packing chocolates into the packets. The chocolate packets here represent an
array of N number of integer values. The task is to find the empty packets(0) of chocolate and push it to
the end of the conveyor belt(array).

Example 1 :
N=8 and arr = [4,5,0,1,9,0,5,0].

There are 3 empty packets in the given set. These 3 empty packets represented as O should be pushed
towards the end of the array

Output:
45195000
# 14 Buy and Sell Stock

Given an array prices[] of length N, representing the prices of the stocks on different days, the task is to find
the maximum profit possible by buying and selling the stocks on different days when at most one transaction
is allowed. Here one transaction means 1 buy + 1 Sell.

Note: Stock must be bought before being sold.

Input: prices[] = {7, 10, 1, 3, 6, 9, 2}


Output: 8
Explanation: Buy for price 1 and sell for price 9.

Input: prices[] = {7, 6, 4, 3, 1}


Output: 0
Explanation: Since the array is sorted in decreasing order, 0 profit can be made without making any
transaction.

prices[] = {4, 10, 1, 3}


# 15 Christmas Tree

Print the pattern given below

*
***
*****
*******
*********
***
***
***
# 16 Counting Valleys

An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly steps, for every
step it was noted if it was an uphill, , or a downhill, step. Hikes always start and end at sea level,

Hackerrank Reference
# 18 Rat count

The function accepts two positive integers ‘r’ and ‘unit’ and a positive integer array ‘arr’ of size ‘n’ as its
argument ‘r’ represents the number of rats present in an area, ‘unit’ is the amount of food each rat consumes
and each ith element of array ‘arr’ represents the amount of food present in ‘i+1’ house number, where 0 <= i
Note:
Return -1 if the array is null
Return 0 if the total amount of food from all houses is not sufficient for all the rats.
Computed values lie within the integer range.

Example:
Input: Explanation:
r: 7 Total amount of food required for all rats = r * unit
unit: 2 = 7 * 2 = 14.
n: 8 The amount of food in 1st houses = 2+8+3+5 = 18. Since, the amount of
arr: 2 8 3 5 7 4 1 2 food in 1st 4 houses is sufficient for all the rats. Thus, output is 4.

Output:
4
# 20 Kth Missing Number

You are given a list arr of N positive integers. You are also given an integer K.

Your task is to find the K-th smallest positive integer that is missing from the list arr.

Constraints

● N (length of arr) and K (1 ≤ N ≤ 10⁵, 1 ≤ K ≤ 10¹²).


● arr[i] (1 ≤ arr[i] ≤ 2*10⁹)

Example 1 Example 2

Inputs Inputs

arr = [2, 5, 7, 15, 5, 13] arr = [2, 4, 5, 7]

k=6 k=7

Output Output

9 11
# 22 Happy Number

Check whether a number is happy number or not

Happy Number - sum of the squares of the digit is equal to 1

Input Format

● A single integer n where 1 <= n <= 10^6

Output Format

● Return True if the number is a happy number, otherwise return False.

Example 1 Example 2 Example 3

Input : 101 Input : 01000 Input : 310

Output : False Output : True Output : False


# 23 Maximum Sum Subarray of Size K

You are given an array arr[] consisting of n integers, and an integer k. Your task is to find the maximum sum of any
contiguous subarray of size k.

Input Format

● The first line contains two integers n and k — the size of the array and the size of the subarray.
● The second line contains n space-separated integers — the elements of the array.

Output Format

● Print a single integer : the maximum sum of any contiguous subarray of size k

Example 1 Example 2

Input : Input :

73 84

2151326 42578125

Output : 11 Output : 22
# 24 Longest Subarray with Sum ≤ S

You are given an array of n positive integers and an integer S. Your task is to find the length of the longest contiguous
subarray whose sum is less than or equal to S.

Input Format

● The first line contains two integers n and S — the size of the array and the maximum allowed sum.
● The second line contains n space-separated positive integers.

Output Format

● Print a single integer — the length of the longest contiguous subarray whose sum ≤ S.

Example 1 Example 2

Input : Input :

8 15 10 20

12345111 5 1 3 5 2 8 1 1 1 10

Output : 5 Output : 6
# 26 Product of Array Except Self

You are given an integer array nums of length n. Return an array answer such that answer[i] is equal to the
product of all the elements of nums except nums[i].

Input Format

● The first line contains an integer n — the size of the array.


● The second line contains n space-separated integers — the elements of nums.

Output Format

● Print n space-separated integers — the product of array elements except self for each index.

Example 1
Input :

4 Output :

1 2 3 4 24 12 8 6

You might also like