Python Coding Problems-1
Python Coding Problems-1
📥 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
📥 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
📥 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
📥 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
📝 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.
📥 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
📥 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
📥 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
📥 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
📤 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
📥 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
📝 Explanation
Digits present in the string are:
2, 3, 4, 5, 6, 7, 8
Total count of digits = 7
Hence, the output is:
7
📥 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
📥 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.
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
📤 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
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
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.
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
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
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.
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
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
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
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
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
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
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
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.
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
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
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
📥 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