0% found this document useful (0 votes)
9 views36 pages

Python Coding Problems-1

The document contains a series of coding questions related to various programming tasks, including calculating sums, finding maximum values, and manipulating strings. Each question provides a problem statement, input and output formats, constraints, and examples for clarity. The tasks range from mathematical calculations to string manipulations and data processing.

Uploaded by

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

Python Coding Problems-1

The document contains a series of coding questions related to various programming tasks, including calculating sums, finding maximum values, and manipulating strings. Each question provides a problem statement, input and output formats, constraints, and examples for clarity. The tasks range from mathematical calculations to string manipulations and data processing.

Uploaded by

sandhyadevi417
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Coding Question: Sum of Remainders


📘 Problem Statement
Perfect Math is an online learning platform. In one of the assignments, the system displays a
list of N integers and an integer value K.
You are required to write a program to calculate the sum of remainders obtained when each
number in the list is divided by K.

📥 Input Format
 The first line contains an integer N, representing the number of elements in the list.
 The second line contains an integer K, the divisor.
 The third line contains N space-separated integers, representing the elements of the
list.

📤 Output Format
 Print a single integer, representing the sum of all remainders after dividing each
number by K.

🧾 Constraints
 1 ≤ N ≤ 10⁵
 1 ≤ K ≤ 10⁵
 0 ≤ List elements ≤ 10⁹

🔍 Sample Input 1
5
3
4 7 10 6 8
🔎 Sample Output 1
5

2.🧑‍💻 Coding Question: Relative Sea Level of Land


📘 Problem Statement
A plot of land is divided into N blocks, and each block is assigned a sea level value.
You are given the sea level values of all blocks.
Write a program to calculate the relative sea level value of the land, defined as the sum of
the minimum and maximum sea level values among all the blocks.

📥 Input Format
1. The first line contains an integer N, representing the number of blocks in the plot of
land.
2. The second line contains N space-separated integers, representing the sea level
values assigned to each block.

📤 Output Format
 Print a single integer representing the relative sea level value of the land, calculated
as:
Relative Sea Level=Minimum value+ Maximum value

📏 Constraints
5
 1 ≤ N ≤ 10
4 4
 −10 ≤ arr [i]≤ 10
 0 ≤ i< N

🧪 Example
Input
5
10 4 5 -1 18
Output
17

📝 Explanation
Sea level values: 10, 4, 5, -1, 18
Minimum value = -1
Maximum value = 18

Relative Sea Level = -1 + 18 = 17

3.🧑‍💻 Coding Question: Reward Points Calculation


📘 Problem Statement
A credit card company has introduced a new functionality for reward points on grocery
items.
A certain number of reward points will be given to a user if they use a credit card for
payment.
The reward points are calculated as the sum of all the digits of the user’s bill amount.
Write a program to calculate and print the reward points based on the given bill amount.

📥 Input Format
 The input consists of a single integer billAmount, representing the user’s bill amount.

📤 Output Format
 Print an integer representing the reward points given to the user.
📏 Constraints
 0 ≤ billAmount ≤ 10⁹
 Programming Language: C / Python
 The solution should work for large bill amounts.

🧪 Example
Input
1234567
Output
28

4.🧑‍💻 Coding Question: Binary Inversion Encryption


📘 Problem Statement
An organization wants to encrypt data stored in multiple data entries.
Each data entry is an integer.
The encryption process for each integer is as follows:
1. Convert the integer into its binary representation (without leading zeros).
2. Invert all bits in the binary representation (change 0 to 1 and 1 to 0).
3. Convert the inverted binary value back into its decimal equivalent.
Write a program to generate the encrypted data for all the given entries.

📥 Input Format
 The first line contains an integer N, representing the number of data entries.
 The second line contains N space-separated integers, representing the data to be
encrypted.

📤 Output Format
 Print N space-separated integers, representing the encrypted values of each data
entry.

📏 Constraints
5
 1 ≤ N ≤ 10
5
 0 ≤ data[i]≤ 10

🧪 Example
Input
4
65 29 56 34
Output
62 2 7 29
📝 Explanation
 65
o Binary: 1000001
o Inverted: 0111110
o Decimal: 62
 29
o Binary: 11101
o Inverted: 00010
o Decimal: 2
 56
o Binary: 111000
o Inverted: 000111
o Decimal: 7
 34
o Binary: 100010
o Inverted: 011101
o Decimal: 29

[Link] Question: Sum of Perfect Squares Between Two Numbers


📘 Problem Statement
A builder wants to know the exact area required for building apartments.
For this purpose, the builder is given two integers representing a range.
Your task is to find and print the sum of all perfect square numbers that lie between the
given two numbers (exclusive).

📝 Note
A perfect square is a number that can be expressed as:
 The product of an integer with itself
 Or the square of an integer
(e.g., 1, 4, 9, 16, 25, …)

📥 Input Format
 The first line contains an integer A
 The second line contains an integer B

📤 Output Format
 Print a single integer representing the sum of all perfect squares between A and B.

📏 Constraints
6
 0 ≤ A < B ≤10
🧪 Example
Input
1
10
Output
13

📝 Explanation
Perfect squares between 1 and 10 are:
 4 (= 2²)
 9 (= 3²)
Sum = 4 + 9 = 13
So, the output is 13.

6.🧑‍💻 Coding Question: Extract Odd Digits from Apartment Data


📘 Problem Statement
A society has multiple apartments, and each apartment has a certain number of people
living in it.
A maximum of 9 people can live in one apartment.
The society wants to develop an automated system that:
 Takes the number of people living in each apartment as input (in string format)
 Extracts and combines only the odd digits
 Forms a new string containing only odd-numbered apartments
Write an algorithm to find and print all the odd digits from the given input.

📥 Input Format
 The input consists of a string numPeople, representing the number of people living in
each apartment.

📤 Output Format
 Print a string containing only the odd digits, in the same order as they appear in the
input.

📏 Constraints
 1 ≤ length of string ≤ 10⁵
 Each character is a digit (0–9)
 Maximum people per apartment ≤ 9
🧪 Example
Input
123456789
Output
13579

📝 Explanation
From the given input:
 Odd digits are: 1, 3, 5, 7, 9
 These digits are combined to form the output string 13579

7.🧑‍💻 Coding Question: Find the Security Key


📘 Problem Statement
A company is securing its data with a security key before transmitting it to another server.
The data is a sequence of digits (0–9).
The security key is identified as the digit having the maximum value in the given data.
Write an algorithm to find and print the security key for the given data.

📥 Input Format
 The input consists of an integer data, representing the data sequence.

📤 Output Format
 Print an integer representing the security key (maximum digit in the data).

📏 Constraints
9
 0 ≤ data≤ 10
 Data contains only digits 0–9

🧪 Example
Input
23567434
Output
7

📝 Explanation
Digits in the data are: 2, 3, 5, 6, 7, 4, 3, 4
The maximum digit is 7.
Hence, the output is 7.

.
8.🧑‍💻 Coding Question: Insert Whitespaces After Fixed Characters
📘 Problem Statement
A bug generates a string without any spaces.
You are given:
 A string S
 An integer charCount
Your task is to insert a whitespace after every charCount characters in the string.
⚠️Note
If the number of remaining characters at the end is less than charCount, they should be
used as they are, without adding extra spaces.

📥 Input Format
1. First line contains a string S
2. Second line contains an integer charCount

📤 Output Format
 Print the formatted string with whitespaces inserted after every charCount
characters.

📏 Constraints
5
 1 ≤∣ S ∣ ≤10
 1 ≤ charCount ≤∣ S ∣
 String contains only lowercase alphabets

🧪 Example
Input
abcdefg
2
Output
ab cd ef g

📝 Explanation
 String = "abcdefg"
 charCount = 2
 Split after every 2 characters:
o "ab", "cd", "ef", "g"
 The last group "g" has fewer than 2 characters, so it remains unchanged.
Final Output:
ab cd ef g
9.🧑‍💻 Coding Question: Total Data Packets Sent Through Network
📘 Problem Statement
A network transmits data in multiple batches.
Each batch contains a certain number of data packets.
You are given:
 The number of batches N
 An array representing the number of data packets in each batch
⚠️Important Note
 Consider zero (0) as a positive number
 Only positive values (including zero) should be counted
 Negative values should be ignored
Write a program to calculate the total count of data packets sent through the network.

📥 Input Format
1. First line contains an integer numBatches (N) — number of batches
2. Second line contains N space-separated integers
(batch₀, batch₁, …, batchₙ₋₁) representing packets in each batch

📤 Output Format
 Print an integer representing the total count of data packets sent through the
network

📏 Constraints
5
 1 ≤ N ≤ 10
5 6
 −10 ≤ batch[i]≤10
 0 ≤ i< N
 Zero is considered positive

🧪 Example
Input
7
2 -3 8 -6 -7 18 1
Output
29

📝 Explanation
Valid (positive or zero) batch values are:
2, 8, 18, 1
Sum:
2 + 8 + 18 + 1 = 29
10.🧑‍💻 Coding Question: Identify Repeated Words in Text
📘 Problem Statement
The online English language skills learning website EngiTip has designed an assessment in
which a piece of text is displayed to students.
The text:
 Contains space-separated words
 Each word is an alphabetic sequence with no whitespaces in between
 Does not contain punctuation marks
Students must identify the words that are repeated in the text more than or equal to N
times.
Such repeated words are automatically removed by the system before the next text is
displayed.
Write an algorithm to display the words that are repeated more than or equal to N times in
the given text.

📥 Input Format
1. The first line consists of a string textInput, representing the text displayed to the
students.
2. The second line consists of an integer N, representing the repetition count threshold.

📤 Output Format
 Print the space-separated words that appear at least N times in the text.
 Print words in the order of their first occurrence.

📏 Constraints
 1 ≤length of text ≤ 105
5
 1 ≤ N ≤ 10
 Text contains only lowercase alphabets and spaces
 No punctuation marks are present

🧪 Example
Input
this is a test this test is simple test
2
Output
this is test

📝 Explanation
Word frequencies:
 this → 2
 is → 2
 test → 3
 a→1
 simple → 1
Words repeated ≥ 2 times are:
this is test

11.🧑‍💻 Coding Question: Reverse Only the Vowels in a Word


📘 Problem Statement
An online English learning platform displays a word to students.
The system wants to generate a new word by reversing only the vowels present in the
original word, while keeping all non-vowel characters in their original positions.
Write a program to reverse the vowels in the given word and print the resulting word.

📥 Input Format
 The input consists of a string originalWord, representing the word displayed to the
student.

📤 Output Format
 Print a string representing the new word after reversing only the vowels in the
original word.

📝 Note
The vowels in the English language are:
a, A, e, E, i, I, o, O, u, U

📏 Constraints
 1 ≤length of the word ≤ 105
 The word contains only alphabetic characters

🧪 Example
Input
heelou
Output
huolee

📝 Explanation
 Original word: heelou
 Vowels in order: e e o u
 Reversed vowels: u o e e
 Replace vowels in original positions with reversed vowels
Result:
huolee

12.🧑‍💻 Coding Question: Generate New Product Name Using Identifier


📘 Problem Statement
A company assigns a single-character name to each product.
To generate a new product name, the system uses an identifier value (N).
The new product name is obtained by shifting the given character backward by N positions
in the English alphabet.
 Alphabetical shifting is cyclic
 Case of the character (uppercase/lowercase) must be preserved
Write an algorithm to print the new name of the product.

📥 Input Format
1. First line contains a character, representing the original product name
2. Second line contains an integer N, representing the identifier

📤 Output Format
 Print a single character representing the new product name

📏 Constraints
 A–Z or a–z
 0 ≤ N ≤ 26

🧪 Examples
Example 1
Input
H
23
Output
E
Explanation
Shifting 'H' backward by 23 positions:
H→E

13.🧑‍💻 Coding Question – Kth Largest Plot Area


📘 Problem Statement
A real estate company owns N land plots, where each plot has a specific area value.
The company wants to identify the Kᵗʰ largest plot area among all the plots to make
business decisions.
Write an algorithm to find and print the Kᵗʰ largest area from the given list of plot areas.
📥 Input Format
1. The first line contains an integer N, representing the number of plots.
2. The second line contains N space-separated integers
area₀, area₁, …, areaₙ₋₁ representing the areas of the plots.
3. The third line contains an integer K, representing the rank of the largest area to be
found.

📤 Output Format
 Print an integer representing the Kᵗʰ largest plot area.

📏 Constraints
6
 1 ≤ N ≤ 10
6
 0 ≤ areai ≤10
 1≤K ≤ N

🧪 Example
Input
7
10 5 7 88 19 45 56
3
Output
45

📝 Explanation
 Given plot areas: 10, 5, 7, 88, 19, 45, 56
 Sorted in descending order:
 88, 56, 45, 19, 10, 7, 5
 The 3rd largest area is 45
Hence, the output is:
45

14.🧑‍💻 Coding Question – Count Numbers Present in an Examination Code


📘 Problem Statement
An online tutoring platform TutoringGuide auto-generates an examination code for various
subjects.
The examination code:
 Is a string
 May contain alphabets (A–Z, a–z), digits (0–9), and whitespaces
 Should ideally contain only alphabets, but due to a system bug, numbers are also
included
The platform wants to count how many numeric digits are present in the examination code.
Write an algorithm to count and print the total number of digits present in the given string.

📥 Input Format
 A single line containing a string textInput, representing the examination code.

📤 Output Format
 Print an integer representing the count of numeric digits (0–9) present in the string.

📝 Note
 The string may contain spaces
 Only digits (0 to 9) should be counted
 Alphabets and whitespaces should be ignored

📏 Constraints
 1 ≤length of string ≤ 105
 String contains only alphabets, digits, and spaces

🧪 Example
Input

aaA 234bcB sadC5678 hsagd


Output
7

📝 Explanation
Digits present in the string are:
2, 3, 4, 5, 6, 7, 8
Total count of digits = 7
Hence, the output is:
7

[Link] Question – Word Finder (Repeated Words)


📘 Problem Statement
Word Finder is an online game in which a player is required to enter a text string.
The game automatically detects the words occurring more than once in the given text.
After the game ends, the repeated words are displayed on the player’s screen.
Write an algorithm to find and display all the words that occur more than once in the
player’s text.

📥 Input Format
 The input consists of a string playerText, representing the text entered by the player.
 The text contains space-separated words.
 A word is an alphabetic sequence with no whitespaces.

📤 Output Format
 Print the space-separated repeated words in lexicographically sorted order.
 If no word is repeated, print:
NA

📝 Note
 Comparison is case-sensitive
 The input text contains only alphabets and spaces
 No punctuation marks are present

📏 Constraints
 1 ≤length of text ≤ 105
 1 ≤number of words ≤ 104

🧪 Example 1
Input
this is a test this test game
Output
test this

📝 Explanation
Word frequencies:
 this → 2
 test → 2
 is, a, game → 1
Repeated words are:
this, test
After lexicographical sorting:
test this

🧪 Example 2
Input
hello world
Output
NA

[Link] Question – Encrypt Data Using Binary Inversion


📘 Problem Statement
A company is transmitting its data to a new server.
There are N files, and each file contains numeric data.
Before transmission, the data of each file is encrypted as follows:
1. Convert the decimal number into its binary representation
2. Invert all the bits of the binary number (change 0 → 1 and 1 → 0)
3. Convert the resulting binary number back into a decimal value
Write an algorithm to encrypt the data of each file using the above steps.

📥 Input Format
1. The first line contains an integer N, representing the number of data entries.
2. The second line contains N space-separated integers, representing the data to be
encrypted.

📤 Output Format
 Print N space-separated integers, representing the encrypted values of the given
data.

📝 Note
 Binary conversion should be done without leading zeros
 Bit inversion should be applied only to the actual binary digits

📏 Constraints
5
 1 ≤ N ≤ 10
6
 0 ≤ datai ≤10

🧪 Example
Input
4
65 29 56 34
Output
62 2 7 29

📝 Explanation
 65 → binary 1000001 → inverted 0111110 → decimal 62
 29 → binary 11101 → inverted 00010 → decimal 2
 56 → binary 111000 → inverted 000111 → decimal 7
 34 → binary 100010 → inverted 011101 → decimal 29
Hence, the output is:
62 2 7 29
18.🧑‍💻 Coding Question – Find the Security Key (Maximum Digit)
📘 Problem Statement
A company secures its confidential data using a security key before sending it to another
server.
The data is provided as a number consisting of digits from 0 to 9.
The security key is defined as the maximum digit present in the given number.
Write an algorithm to identify and print the security key.

📥 Input Format
 The input consists of a single integer data, representing the data sequence.

📤 Output Format
 Print an integer representing the security key (largest digit in the data).

📏 Constraints
9
 0 ≤ data≤ 10
 The number contains only digits (0–9)

🧪 Example
Input
23567434
Output
7

📝 Explanation
Digits in the given number:
2, 3, 5, 6, 7, 4, 3, 4
The maximum digit is 7, which is the security key.

[Link] Problem: Maximum Horses Bob Can Bet On


Problem Statement
Bob is going to place a bet on a horse race. There are N horses, arranged in a sequence
from 1 to N.
Each horse has a different betting price.
Bob believes that betting on continuous horses gives him a better chance of winning.
However, Bob has only K units of money, and the total betting price must be strictly less
than K.
Your task is to find the maximum number of consecutive horses Bob can bet on.
If more than one such sequence exists, Bob will choose any one of them.
Input Format
NK
P1 P2 P3 ... PN
Where:
 N = number of horses
 K = maximum money Bob can spend
 Pi = price of betting on the i-th horse

Output Format
Print a single integer representing the maximum length of a continuous sequence.

Constraints
 2 ≤ N ≤ 10^5
 1 ≤ Pi ≤ 10^5
 1 ≤ K ≤ 10^9

Sample Input 1
5 10
23143
Sample Output 1
3
Explanation
The maximum continuous sequence whose sum is less than 10 is:
[3, 1, 4] → sum = 8

[Link] Problem: Golden House Puzzle


Problem Statement
You visit a Golden House that contains N rooms, arranged in a straight line from Room 1 to
Room N.
Each room contains a certain number of gold coins.
You must start from Room 1 and move forward.
In each room, you may either:
 Collect all coins in that room, or
 Skip the room and move to the next one
⚠️Rule:
If you collect coins from a room, you must skip the next room (you cannot collect coins from
two adjacent rooms).
Your task is to find the maximum number of coins you can collect.
📥 Input Format
N
C1 C2 C3 ... CN
Where:
 N → number of rooms
 Ci → number of gold coins in the i-th room

📤 Output Format
Print the maximum coins that can be collected.

📌 Constraints
 1 ≤ N ≤ 10^5
 0 ≤ Ci ≤ 10^9

🧪 Sample Input 1
5
6 7 1 30 8
✅ Sample Output 1
37

21.🧩 Problem: ASCII Pair Maximum


Problem Description
You are given a string S consisting of English alphabet characters.
Your task is to generate a new string by processing the input string two characters at a time.
For each consecutive pair of characters:
 Compare their ASCII values
 Append the character with the higher ASCII value to the result string
If the string has an odd length, append the last character directly to the result.

Input Format
 A single line containing the string S

Output Format
 Print the resulting string after applying the above logic

Constraints
 1 ≤ |S| ≤ 10⁵
 S contains only uppercase and/or lowercase English letters

Sample Input 0
abcd
Sample Output 0
bd

Sample Input 1
abcde
Sample Output 1
bde

Explanation
 (a, b) → b (higher ASCII)
 (c, d) → d (higher ASCII)
 Last character e is appended as it has no pair
Resulting string: bde

22.🧩 Problem: Frequent Words Filter


Problem Description
An online English learning website analyzes user-written sentences to identify commonly
repeated words.
You are given a sentence and an integer X.
Your task is to find all the words that occur at least X times in the sentence.
The qualifying words must be:
 Unique
 Sorted in lexicographical (alphabetical) order
Finally, print them as a space-separated string.

Input Format
 The first line contains a string representing a sentence
 The second line contains an integer X

Output Format
 Print all words that appear X or more times, sorted alphabetically and separated by
spaces
 If no word satisfies the condition, print an empty line

Constraints
 1 ≤ Length of sentence ≤ 10⁵ characters
 1 ≤ X ≤ 10⁵
 The sentence contains only lowercase English letters and spaces

Sample Input 0
this is a test this is a test this
2
Sample Output 0
is test this

Explanation
Word frequencies:
 this → 3
 is → 2
 test → 2
 a→1
Words with frequency ≥ 2 are is, test, and this, which are printed in alphabetical order.

23🧩 Problem: Difference Between Number and Its Reverse


Problem Description
A mobile company uses a simple numeric transformation as part of its coding assessment.
You are given an integer N.
Your task is to:
1. Reverse the digits of the number N
2. Find and print the difference between the original number and its reversed number

Input Format
 A single integer N

Output Format
 Print a single integer representing N − reverse(N)

Constraints
 0 ≤ N ≤ 10⁹

Sample Input 0
123
Sample Output 0
-198

Explanation
 Original number = 123
 Reversed number = 321
 Difference = 123 − 321 = -198

24 🧩 Problem: Difference Between Most and Least Frequent Product Codes


Problem Description
A company tracks product usage using product codes.
Each product code may appear multiple times in the system logs.
You are given:
 An integer N, representing the number of product codes
 A list of N integers, representing the product codes
Your task is to:
1. Identify the product code with the maximum frequency
2. Identify the product code with the minimum frequency
3. Print the difference between these two product codes
If multiple product codes have the same maximum or minimum frequency, consider the
latest occurring code.

Input Format
 The first line contains an integer N
 The second line contains N space-separated integers representing product codes

Output Format
 Print a single integer representing
(Most Frequent Product Code − Least Frequent Product Code)

Constraints
 1 ≤ N ≤ 10⁵
 0 ≤ Product Code ≤ 10⁹

Sample Input 0
6
10 20 20 30 10 20
Sample Output 0
10

Explanation
Frequencies:
 10 → 2 times
 20 → 3 times
 30 → 1 time
 Most frequent product code → 20
 Least frequent product code → 10
 Difference → 20 − 10 = 10

25🧩 Problem: Separate Prime and Non-Prime Numbers


Problem Description
In a coding test, a company evaluates your understanding of number theory and loops.
You are given a list of N integers.
Your task is to:
1. Identify prime numbers
2. Identify non-prime numbers
3. Print all prime numbers first, followed by all non-prime numbers, maintaining their
original order within each group.

Input Format
 The first line contains an integer N
 The second line contains N space-separated integers

Output Format
 Print the prime numbers followed by non-prime numbers in a single line
 Numbers should be separated by a space

Constraints
 1 ≤ N ≤ 10⁵
 0 ≤ Each number ≤ 10⁹

Sample Input 0
6
245679
Sample Output 0
257469

Explanation
 Prime numbers: 2, 5, 7
 Non-prime numbers: 4, 6, 9
Printed output places all primes first, followed by non-primes.

26 🧩 Problem: Maximum Pair Sum and ASCII Range


Problem Description
In a company coding assessment, you are required to perform two operations based on the
given inputs.
1. From a list of integers, determine the sum of the two largest numbers, provided the
list size is within a valid range.
2. From a given string, determine the minimum and maximum ASCII values among its
characters.
Both results must be printed in the order specified.

Input Format
1. An integer N, representing the number of elements
2. N space-separated integers, representing the array elements
3. A string S

Output Format
 First line: Print the sum of the two largest numbers in the array
 Second line: Print two integers representing the minimum and maximum ASCII
values in the string

Constraints
 2 ≤ N ≤ 1,000,000
 0 ≤ Array elements ≤ 10⁹
 1 ≤ Length of S ≤ 10⁵
 S contains printable ASCII characters

Sample Input
5
39174
abcZ
Sample Output
16
90 99

Explanation
 The two largest numbers in the array are 9 and 7 → Sum = 16
 ASCII values of string characters:
o Z → 90
o a → 97
o b → 98
o c → 99
Minimum ASCII value = 90
Maximum ASCII value = 99

27 🧩 Problem: Common Power-Up Divisors


Problem Description
A gaming hub uses numeric power-up codes to unlock special features in a game.
You are given:
 An integer N, representing the number of power-up codes
 A list of N integers, representing the power-up values
 Two integers K and J, representing two special game levels
Your task is to count how many power-up values exactly divide both K and J.
A power-up value a is considered valid if:
 K % a == 0 and
 J % a == 0

Input Format
1. An integer N
2. N space-separated integers, representing power-up values
3. Two space-separated integers K and J

Output Format
 Print a single integer representing the count of valid power-up values
Constraints
 1 ≤ N ≤ 1000
 0 ≤ Power-up values ≤ 1000
 0 ≤ K, J ≤ 1000

Sample Input
5
12346
12 24
Sample Output
4

Explanation
Power-up values that divide both 12 and 24:
 1 → divides both
 2 → divides both
 3 → divides both
 6 → divides both
Count = 4

28🧩 Problem: Difference Between Maximum and Minimum Pair Product


Problem Description
In a coding challenge, you are given a list of integers.
Your task is to:
1. Compute the product of every distinct pair of elements in the list
2. Identify the maximum product and the minimum product
3. Print the difference between the maximum and minimum products

Input Format
 An integer N, representing the number of elements
 N space-separated integers, representing the elements of the list

Output Format
 Print a single integer representing
(Maximum Pair Product − Minimum Pair Product)

Constraints
 2 ≤ N ≤ 10⁵
 −10⁵ ≤ Array elements ≤ 10⁵
Sample Input
4
1 3 -2 4
Sample Output
14

Explanation
All distinct pair products:
 1×3 = 3
 1×(−2) = −2
 1×4 = 4
 3×(−2) = −6
 3×4 = 12
 (−2)×4 = −8
 Maximum product = 12
 Minimum product = −8
Difference = 12 − (−8) = 20

29 🧩 Problem: Digit Sum to Alphabet Conversion


Problem Description
In an online test, candidates are given a number-based puzzle involving digit sums and
alphabet mapping.
You are given a positive integer N. Perform the following steps:
1. Calculate the sum of digits of the number N.
2. If the digit sum is less than or equal to 26:
o Convert the digit sum to a corresponding uppercase English alphabet
o (1 → A, 2 → B, …, 26 → Z)
3. If the digit sum is greater than 26:
o Print the digit sum
o Then compute the sum of digits of this digit sum
o Convert the new sum to its corresponding uppercase English alphabet

Input Format
 A single integer N

Output Format
 If the digit sum ≤ 26, print the corresponding uppercase letter
 If the digit sum > 26:
o Print the digit sum on one line
o Print the corresponding uppercase letter of its digit-sum on the next line
Constraints
 1 ≤ N ≤ 10⁹

Sample Input 0
123
Sample Output 0
F
Explanation
 Sum of digits = 1 + 2 + 3 = 6
 6 corresponds to F

30🧩 Problem: Digit to Alphabet Encoding


Problem Description
Cosmotic, a tech company, uses a special encoding technique to convert numeric product
IDs into alphabet-based codes.
You are given a non-negative integer N.
Each digit of the number is mapped to a lowercase English alphabet character as follows:
Digit Character
0 a
1 b
2 c
3 d
4 e
5 f
6 g
7 h
8 i
9 j
Your task is to convert the given number into its corresponding encoded string using the
above mapping.

Input Format
 A single integer N

Output Format
 Print the encoded string

Constraints
 0 ≤ N ≤ 1,000,000
Sample Input 0
120
Sample Output 0
bca

Explanation
 Digit 1 → b
 Digit 2 → c
 Digit 0 → a
Encoded string = bca

31🧩 Problem: Separate Even and Odd Numbers


Problem Description
A teacher is evaluating students’ understanding of loops and conditional statements.
You are given a list of integers.
Your task is to:
1. Identify whether each number is even or odd
2. Separate all even numbers and odd numbers
3. Print all even numbers first, followed by all odd numbers
(maintaining their original order within each group)

Input Format
1. An integer N, representing the number of elements
2. N space-separated integers, representing the list

Output Format
 Print all even numbers first (without spaces)
 Then print all odd numbers (without spaces)

Constraints
 0 ≤ N ≤ 1000
 0 ≤ Each element ≤ 10⁵

Sample Input
5
12345
Sample Output
24135
Explanation
 Even numbers → 2, 4
 Odd numbers → 1, 3, 5
Printed output = 24135

32 Problem: Lucky Lottery Number


Problem Description
In a lucky lottery system, some numbers appear more frequently than others.
You are given:
 An integer N, representing the number of lottery tickets
 A list of N integers, representing the lottery numbers
Your task is to find and print the lottery number that appears the maximum number of
times.
If multiple numbers have the same highest frequency, print the one that appears first in the
list.

Input Format
1. An integer N
2. N space-separated integers, representing lottery numbers

Output Format
 Print a single integer representing the most frequent lottery number

Constraints
 1 ≤ N ≤ 10⁵
 0 ≤ Lottery numbers ≤ 10⁹

Sample Input
7
4243245
Sample Output
4

Explanation
Frequencies:
 4 → 3 times
 2 → 2 times
 3 → 1 time
 5 → 1 time
The number 4 appears the most, so it is printed.
[Link]: Swap Consecutive Digits in Encrypted Code
Problem Description
A company encrypts numeric codes by swapping every pair of consecutive digits.
You are given a non-negative integer N.
Your task is to generate the encrypted code by applying the following rules:
1. Swap every pair of consecutive digits
2. If the number of digits is odd, keep the last digit unchanged
3. Print the resulting encrypted number as a string

Input Format
 A single integer N

Output Format
 Print the encrypted code after swapping consecutive digits

Constraints
 0 ≤ N ≤ 1,000,000

Sample Input 0
1234
Sample Output 0
2143

Sample Input 1
12345
Sample Output 1
21435

Explanation
 Input 1234 → swap (1,2) and (3,4) → 2143
 Input 12345 → swap (1,2) and (3,4), keep 5 → 21435

[Link] Description
A system generates a Bucket ID using a special rule based on the digits of a number.
You are given a positive integer N.
Follow the steps below to generate the final Bucket ID value:
1. Extract all digits of the number N
2. Arrange the digits in descending order to form one number
3. Arrange the digits in ascending order to form another number
4. Convert both results to integers
5. Print the sum of these two numbers

Input Format
 A single integer N

Output Format
 Print a single integer representing the sum of the descending-order number and
ascending-order number

Constraints
 1 ≤ N ≤ 10⁹

Sample Input 0
4213
Sample Output 0
7666

Explanation
Digits of the number: 4, 2, 1, 3
 Descending order → 4321
 Ascending order → 1234
Sum = 4321 + 1234 = 5555

35.🧩 Problem: Container Pair Arrangement


Problem Description
A logistics company stores containers identified by numeric IDs.
To optimize transportation, the containers must be arranged in a special pairing order.
You are given:
 An integer N, representing the number of containers
 A list of N integers, representing container IDs
Your task is to:
1. Sort the container IDs in ascending order
2. Form pairs by alternately selecting:
o The largest remaining ID
o The smallest remaining ID
3. Print each pair on a new line

Input Format
1. An integer N
2. N space-separated integers, representing container IDs

Output Format
 First, print the sorted list of container IDs
 Then, print pairs of container IDs in the specified order
(largest, smallest), one pair per line

Constraints
 1 ≤ N ≤ 10⁵
 0 ≤ Container IDs ≤ 10⁹

Sample Input
6
419275
Sample Output
[1, 2, 4, 5, 7, 9]
91

72

54

Explanation
Sorted container IDs: [1, 2, 4, 5, 7, 9]
Pairs formed:
 (9, 1)
 (7, 2)
 (5, 4)
Each pair contains the largest and smallest remaining container IDs.

36.🧩 Problem: Common Divisor Players Count


Problem Description
In a sports analytics system, each player is assigned a unique number.
You are given:
 An integer N, representing the number of players
 A list of N integers, representing player numbers
 Two integers A and B, representing match scores
A player number is considered eligible if it exactly divides both A and B.
Your task is to count and print the number of eligible players.

Input Format
1. An integer N
2. N space-separated integers, representing player numbers
3. Two space-separated integers A and B

Output Format
 Print a single integer representing the count of eligible players

Constraints
 1 ≤ N ≤ 1000
 1 ≤ Player numbers ≤ 1000
 0 ≤ A, B ≤ 10⁹

Sample Input
5
12346
12 24
Sample Output
4

Explanation
Player numbers that divide both 12 and 24:
 1, 2, 3, 6
Count = 4

37.🧩 Problem: Sum of Fibonacci Balloons


Problem Description
In a game event called Balloons, balloons are released following a Fibonacci pattern.
You are given an integer N, representing the number of balloon levels.
Each level corresponds to a Fibonacci number starting from 0.
Your task is to calculate and print the sum of the first N Fibonacci numbers.

Input Format
 A single integer N

Output Format
 Print a single integer representing the sum of the first N Fibonacci numbers

Constraints
 0 ≤ N ≤ 100000

Sample Input 0
5
Sample Output 0
7

Explanation
First 5 Fibonacci numbers:
0, 1, 1, 2, 3
Sum = 0 + 1 + 1 + 2 + 3 = 7

Notes
 Fibonacci sequence starts with 0 and 1
 For N = 1, the sum is 0
 Input value is guaranteed to be within the valid range

38.🧩 Problem: Balloon Fibonacci Sum


Problem Description
In a balloon festival game, balloons are released in a pattern that follows the Fibonacci
sequence.
You are given an integer N, representing the number of stages.
At each stage, the number of balloons released follows the Fibonacci sequence starting from
0.
Your task is to calculate and print the sum of the first N Fibonacci numbers.

Input Format
 A single integer N

Output Format
 Print a single integer representing the sum of the first N Fibonacci numbers

Constraints
 0 ≤ N ≤ 100000

Sample Input 0
6
Sample Output 0
12

Explanation
First 6 Fibonacci numbers:
0, 1, 1, 2, 3, 5
Sum = 0 + 1 + 1 + 2 + 3 + 5 = 12

39 Problem: Examination Code Analysis & Perfect Math Remainders


Problem Description
This problem consists of two tasks that test string processing and mathematical operations.

🔹 Task 1: Count Numeric Characters in Examination Code


You are given a string representing an examination code.
Your task is to count how many numeric characters (0–9) are present in the string.

🔹 Task 2: Perfect Math – Sum of Remainders


You are given:
 An integer K (divisor)
 An integer N (number of elements)
 A list of N integers
Your task is to calculate the sum of remainders obtained when each element in the list is
divided by K.

📥 Input Format
1. A string S (Examination code)
2. An integer K
3. An integer N
4. N space-separated integers

📤 Output Format
 First line: Print the count of numeric characters in the string
 Second line: Print the sum of remainders

🧾 Constraints
 1 ≤ Length of S ≤ 10⁵
 1 ≤ K ≤ 10⁵
 1 ≤ N ≤ 10⁵
 0 ≤ List elements ≤ 10⁹

🔍 Sample Input
EXAM2025CODE
3
5
4 7 10 6 8
🔎 Sample Output
4
5

🧪 Explanation
Task 1
String: EXAM2025CODE
Numeric characters: 2, 0, 2, 5
Count = 4
Task 2
Remainders when divided by 3:
 4%3=1
 7%3=1
 10 % 3 = 1
 6%3=0
 8%3=2
Sum = 1 + 1 + 1 + 0 + 2 = 5

📝 Notes
 Digits are identified using character properties
 Modulo ope

You might also like