0% found this document useful (0 votes)
152 views21 pages

Coding Challenges for Beginners

The document contains a series of programming questions that require solving various computational problems using Python. Each question includes input specifications, output specifications, and examples to clarify the requirements. Topics covered include string manipulation, array operations, mathematical calculations, and algorithmic challenges.

Uploaded by

228w1f0045
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)
152 views21 pages

Coding Challenges for Beginners

The document contains a series of programming questions that require solving various computational problems using Python. Each question includes input specifications, output specifications, and examples to clarify the requirements. Topics covered include string manipulation, array operations, mathematical calculations, and algorithmic challenges.

Uploaded by

228w1f0045
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/ 21

Question 1

How to Attempt?
Character Count
PYTHONS
Revisit Later
You are given a string S of length N. Your friend wants to know the number of times his favorite letter C occurs in the string.
Your task is to help your friend find and return an integers er value representing the number of times a character occurs in a
particular string.
Notes All the characters in the seco
Input Specification:
input1: A string S
input2: An integer N, representing the
input3: A character
Output Specification:
Return an Integer value representing the character occurs in a particular string
Example 1:
input1: helloworld
input2: 10
Inputs: 1
Output:3
Question 2
How to Attempt?
PYTHON3
Revisit Later
Find Dividend
You are given array A, having some dividends. Further, you are given 3 numbers D. Q and R. A dividend can be found using a
rule that states:
input2: int
input3 int
Dividend Divisor x Quotient + Remainder
input4 int
inputs int
Your task is to find and return an integer value representing the index of the dividend if present in array. If dividend not found
return-1.
Input Specification:
input1: An integer array A containing dividends
input2: An integer D, representing diviso
input3: An integer Q representing quotient
input4: An integer R, representing remainder
Expected return type: int
return i
return -1
Output Specification:
Return an integer value representing the index of the dividend if present in array. If dividend not found return 0.
24
3670

Question 3
PYTHON3
How to Attempt?
Vowel Permutation
You are given a string S and your task is to find and return the count of permutations formed by fixing the positions of the
vowels present in the string.
Expected return type: int
Note:
#Read only region end
Ensure the result is non-negative
If there are no consonents then return 0
Input Specification:
input1: A string S
Output Specification:
Return an integer value representing the count of permutations formed by fixing the positions of the vowels present in the
string.
Example 1:
input: AB of the daily temperatures (in Celsius) for each day of your expedition in the form of an array A. Your task is to find
and return the longest consecutive period (in days) where the temperature drops for at least 3 days

Question 4
Arctic Temperature Tracker
You are leading an Arctic expedition and need to closely monitor the temperature: ensure the safety of your team. Your tracker
has records
Revisit Lter
Attempted: 1/2 PYTHON3
Expected return type: int
Input Specification:
input1: An integer array A representing the temperature for each. Input2: An integer value, representing the size of the array.
Output Specification:
Retum an integer value renresenting the Innnest consentive nerind
Use Custom Input
Question 5
White Space Difference
You are given 2 strings A and B. Your task is to find and return a string saying 'Even'
if the value representing the absolute differences between the number of whitespaces in both the strings is divisible by 2 else
Odd' if the value representing the absolute differences between the number of whitespaces in both the strings the whitespace is
not divisible by 2 along with the difference value
Input Specification:
input1: A string A
input2: A string E

Output Specification:
Retum a string saying 'Even if the value representing the absolute differences between the number of whitespaces in both the
strings is divisible by 2 else Odd if the value representing the absolute differences between the number of whitespaces in both
the strings the whitespace is not divisible by 2.
Example 1:
input1: "Hello World"
input2: "Hello World"
Output: Even4
Question 6
Halloween Candies
Sab goes to super market to shop candies represented by an array A for handween party, his mother gave him some money M.
Dus to the festive season, there are several offers in the supermarket. One such offer useful for Bob is, if the price of the candy
is a multiple of 5, he can buy it without spending any money otherwise he will spend money equal to At which is the price of a
particular candy Bob can shop as long as he has money. Your task is to find and return the maximum number of candles Bob
can buy.
Noter Assume 1-based indexing
Input Specification:
inputt: An integer value, representing number of candles input2: An Integer array A, representing price of each candy. Input3:
An integer value M, representing the amount of money,
Output Specification:
Return the number of candles Bob can buy.
Example 1:
input1:3
input2: 55.105)
inputs: 15
Question 7
Poet and Rhymes
A poet has asked you for assistance in writing poems. He has given you a string S and a dictionary D and he asks you to find,
from the dictionary, a word which rhymes best with 5. Words are said to myme when the last syllables of the words are the
same, like "cave" and "gave", or "typical" and "critical" The words will be deemed to rhyme best if the last few characters of
the words, match the most.
Note
fall the characters match, it is the same ward and net a fyming word
All the pier words are un invercome
mutileming wests are found then choose the word with the lesindex
Input Specification:
input1:A string values, representing a single word
Input2: & string array D, representing the dictionary
input3 Ar integer value representing the length of array D
Output Specification:
Returasting value denting the word which thymes best with S from the dictionary each word is found return the string "No
Word
Question 8
Island Life
You are stuck on an island where they sell and eat coconut sweets only. A person can buy at most 1 box per day with each box
containing N pieces. To remain alive, you must consume E coconut sweets daily for D days. but the catch is that you cannot
purchase sweets on Sundays. Your task is to find and return an integer value representing the minimum number of times you
have to buy coconut sweets in order to stay alive. If not possible, return -1.
Note: The day starts from Monday
Attempted: 2/2 PYTHON3
Compile and Test
Compiler: Python 3.11
input3: int
Expected return type: int
input1: An integer value N. representing the number of coconut sweets per box.
input2: An integer value E. representing the number of coconut sweets you must eat daily.
input3: An integer value D, representing the number of days you have to spend on the island.
Output Specification:
45128
Return an integer value representing the minimum number of times
Use Custom Input
Question 9
Rebound Height
Daniel has a ball. He wants to find the ball's rebound height, which he dropped from height H with an initial velocity V. After
the N rebound the final velocity of the ball is V, Your task is to help him find and return an integer value representing the
height to which the ball rebounds after N bounces
Compile and Test
inputi: int
input2 int
input3 int
where H is the rebound height His the initial height, e is the coefficient of restitution and is the number of bounces
Expected return type: Int
VNV, where Vis the initial velocity and V, is the final velocity
Input Specification:
input2/ input3
7683
1367
1923
input1: An integer H. representing initial height
Input2: An integer V. representing initial velocity
input3: An integer V,, representing final velocity
Output Specification:
Return an integer value representing the height to which the ball rebounds after N bounces
Question 10

Maximize Pair Product


Noah is given an integer array A of length N. He must perform the
following operations
Select any integer pair having sum equal to 18 from the array.
Expected return type: int[]
#Read only region end
Select the pair with maximum product such that the first element of the pair is greater than the second
element of the pair.

Your task is to help Noah find and return a pair in the form of an integer array, which satisfies the
mentioned conditions.
Input Specification:
return x
input1: An integer value N, representing the size of array A. input2: An integer array A
Output Specification:
Rehim anair in the form of an intoner arra which satisfies the
Question 11
Reverse Array an been given an array A of length N and he wants to And the sum of even posticips
after revoring the array. Your task is to help him find and retint arinti
value representing sum of the array elements present the even positions of the rewarsed
Input Specification:
Input A reversco etager at
input2: An integer be representing /
Output Specification
Resim an integer
elements present et chiei inte

Question 12

How is Attemper
Maximum Permutation Value
Revisit Later
You are given a string array of lengts N. Your task is to find and reture an integer value representing
the maximum permutation count of the strings after removing all the vowels from every element in the
string array
Note
Consider at the lowering and word then
output Specification
imputing etter lengre N input2integer v represent
eting the size of the string array
Inputs: stret
Expected return type Int
Example 3:
inputs theo ccticame

You are given two strings A and B. Your task is to find and return a string representing the leftover
string in A after removing all the letters that
6
7
inputi: string
exist in string B. Return "Empty" if the output does not contain any value.
8
inputz: string
9
10
Note:
11
Strings A and B contain English alphabets in upper case only
12
Expected return type: string
# Read only region end.
13

#Write code here


A single alphabet in B con replace all the occurrences of that alphabet in A.
14
res
15
for char in input:
Input Specification:
16
if char not in input2:
input1: A string A
input2: A string 8
17
res+-char
18
If res:
19
return res
20
else:
Output Specification:
Return a string representing the leftover string in A after removing all the letters that exist in string B
21
return "Empty"
IntelliSense is loading
Example 1:Use Custom Input
Question 13

Your friend has problem in reading the time if a dock follows 24-hour format so you decide to help him
out. You have two integers X and Y Your task is to find and return an integer value representing the
product of these two integers in the 12 hour system.
Input Specification:
input1: An integer value X
input2: An integer value Y
Output Specification:
Return an integer value representing the product of the bid integers in the 12- hour system
Example 1:
Input1:4
Input2:5
Output: A
Message:
Clock problem. Language: python
Question 14

Alice and String

Alice has a peculiar fondness for strings without any interruptions. She considers" as an interruption. You
are given a string 5 and your task is to find and return the length of the longest uninterrupted substring to
match alices fondness.

Example 1:
input: abc.b.or
Output: 3
Explanation:
Here, the given string is "abcb.cc, it contains three substrings ("abc": "b"cc") without

Message:
Alice and string.
Question 15

Second Occurrence
Charles is given an array A. He wants to find the count of occurrence c element in the array. Your task is to
help him tind and rerum anveger va representing the count of occurrence of the second largest element in an
array
Note:
If the may contains the same elements, then
The may has only consecutive elements
Input Specification:
Input1: An integer N. representing length of array.
Input2: An integer array A
Output Specification:
Return an integer value representing the count of
element in an array
Example 1
input1:0
Input2:11, 21.44.5.5.31
Message:
Second occurrence.
FARSC
Canopy Area
You are developing a feature for an environmental awareness app that helps users to know how much area
their tree's shadow covers. You have the distance D from a tree's trunk to the edge of the shadow. Your
task is to calculate and return an integer value representing the shadow area of the canopy.
Nate Round off the tutto nearest integer
Input Specification:
Input1: An integer value D. representing the distance from the tree trunks to
the edge of shadow.
Output Specification:
Return an integer value representing the shadow area of the canopy.
Example 1:
Input1:5
Output: 78
Explanation:
Here D& So area of the canopy would be Themelore will be returned as output
elliSense has icaded
Question 16

There is a competition in a school. A qualifying score of 35 marks or more has been set as the cut-off to
take part in t this competition.
There are N subjects taught in a class. The marks obtained in each subject in semesters 1 and 2 are gen in
the form of two arrays 51 and 52 espectively. The qualifying scone is calculated in the following way
Step 1 Subtract the marks obtained in the subject in Semester from the marks obrained in the subject in
Semester 2 Le, 52- 512 where i-0,1,2.
Step 2: Add the marks of upto P subjects with the maximum scores obtained after the subtraction in Step 1.
The will give a student's qualifying score. The aim is to get a score equal to or greater than
If the qualifying scora reater than or equal to 35 these student
ition to partidetean the dompetition wise they are disqualified Your tek is to hid and run a string van
representing the rest Qualified or Disqualified flowed by the score achieved separated by zapace
Input Specification:
input: An integer value & repeserting the number of subjects taught
Question 17
Bitwise Operation
You are given two integers A and B Your task is to find and return an integer representing the value of
their bitwise OR operation
Note these is any operator which set at least one of the others A operator as evaluates both the
FORD T
• CORDIO

Question 18

Special Fibonacc
Alex is exploring a series and she came across a special series, in which RN) = F(N-1) RN-1)+RN-2) FN-
2)
where (0) 1,f1=1
Your task is to help Alex find and return an integer value, representing the N number in this special series
Note: Return the output modulo 47.
Input Specification:
input int
Output Specification
return an integer value representing the Nth number in this special series
Question 19

Even Odd
Jack has an array A of length N. He wants to label whether the number in the array
even or odd. Your task is to help him find and return a string with labels even or odd in sequence according
to which the numbers appear in the array.
Input Specification:
Input1: An integer array A, representing the array of numbers Input2: A integer N, representing the length of
array
Output Specification:
Return a string with labels even or odd in sequence according to which the numbers appear in the array.
Example 1:
Input1:[1,2,3,4,5,6)
Input2: 6

Message:
Even odd. Language: python
Question 20
File Version: You are given a string array S that contains the names of some files along with their versions. Your
task is to find and return an integer value representing the latest version out of all the files that are correctly named
in the array. A file is considered correct if it follows the format of the file named as "File X" (where X represents
the file version number). Return -1 if there are no correct files in the array.
Note:
 A file is is incorrect if the name of the file does not match.
 if there is no file in the files array then also return -1.
Input Specification:
 input1: A string array S, representing the names of the files.
 input2: An integer value representing the size of the array.

Logic:
if input2==0:
return -1
max_version=-1
for f in input1:
x-=f.strip().split("-")
if x[0]==File" and x[1].isdigit(): max_version=max(max_version, int(x[1]))
return max_version

You might also like