Problem Title: The HOD's Selection
Problem Statement
The Head of Department (HOD) at an engineering college is selecting a class monitor. The HOD
maintains a list of potential candidates based on their JEE Mains rank.
The HOD follows these rules:
1. Candidates arrive one by one in the order they enter the room.
2. The HOD wants the list to be strictly increasing in "quality" (which means strictly
decreasing in rank number, since a lower rank is better).
3. When a new student arrives with rank R:
o Any student already in the list whose rank is higher (worse) than or equal to R is
permanently removed (cut) from the list.
o The new student is then added to the end of the list.
Given an array of ranks in the order of the students' arrival, calculate the total number of names
that were cut from the list by the time all students have arrived.
Input Format
• The first line contains an integer N, the number of students.
• The second line contains N space-separated integers representing the ranks of the
students in arrival order.
Output Format
• Print a single integer representing the total number of students removed from the list.
Example Case
Input:
100 50 80 40 60
Output:
Explanation:
1. Student 1 (Rank 100): List is [100]. Cuts: 0.
2. Student 2 (Rank 50): 50 is better than 100. 100 is cut. List is [50]. Total Cuts: 1.
3. Student 3 (Rank 80): 80 is worse than 50. Nothing cut. List is [50, 80]. Total Cuts: 1.
4. Student 4 (Rank 40): 40 is better than 50 and 80. Both are cut. List is [40]. Total Cuts: 3.
5. Student 5 (Rank 60): 60 is worse than 40. Nothing cut. List is [40, 60]. Total Cuts: 3.
Here are the coding questions we discussed, organized into a clean, scannable Markdown
format suitable for a coding platform or study guide.
2. The Segmented Sequence (Modulo & Continuity)
Scenario: Splitting a sequence based on mathematical and sequential rules.
Problem Statement
Split an array into the minimum number of contiguous subarrays. A split occurs if:
1. nums[i] mod k != nums[i-1] mod k
2. nums[i] != nums[i-1] + 1
Example
Input: nums = [10, 11, 15, 16], k = 5
Output: [[10, 11], [15, 16]]
Explanation: 11 follows 10 (consecutive, but mod changes: 10%5=0, 11%5=1). Split!
Example Case
Input: nums = [2, 3, 4, 10, 12, 13, 15], k = 2
Output: [[2, 3, 4], [10], [12, 13], [15]]
This problem involves simulating or mathematically calculating the state of a bit array over
multiple cyclic shifts (rotations).
Problem Title: Cyclic Bit Accumulator
Problem Statement
You are given a binary array arr of size N consisting of only 0s and 1s, and an integer K.
The array undergoes K total rotations. In each rotation, the array is shifted right by one position
(the last element moves to the front).
Your task is to calculate how many times a 1 appears at each specific index i across all K rotations
(including the initial state as the 0-th rotation). Finally, return a string or an array representing
these counts.
Note: For the sample provided, if the input is 1 0 1 0 and the output is 3, it implies we are looking
for the count of 1s at a specific index (like index 0) throughout K rotations.
Input Format
• The first line contains the binary array arr (space-separated).
• The second line contains the integer K (number of rotations).
Output Format
• A string representing the total count of 1s observed at the target index (typically index 0)
across all K+1 states.
Logic Visualization
When an array rotates, the element that ends up at index 0 follows a predictable pattern: it is
simply the elements of the original array scanned backwards (circularly).
Example Case
Input:
1010
Output:
Step-by-Step Breakdown:
• Initial (0 rotations): [1, 0, 1, 0] -> Index 0 is 1.
• 1st Rotation: [0, 1, 0, 1] -> Index 0 is 0.
• 2nd Rotation: [1, 0, 1, 0] -> Index 0 is 1.
• Total 1s at Index 0: 1 + 0 + 1 = 2.
(Note: If your sample output was 3 for 1 0 1 0, it suggests K=4 or a different specific rotation
count. The logic below scales to any K.)
Problem Title: The Sign-Based Segmenter
Problem Statement
Given an array of integers nums, your task is to find the total number of segments.
A segment is defined as a maximal contiguous subarray where all elements share the same sign
property. Specifically:
1. All elements in the segment are positive (> 0).
2. OR all elements in the segment are negative (< 0).
A segment ends (and a new one begins) whenever the sign of the numbers flips from positive to
negative or vice versa. For this problem, you can assume the input contains no zeros.
Input Format
• A single line containing space-separated integers.
Output Format
• A single integer representing the total number of segments.
Example Case
Input:
1 3 5 -2 -6 8
Output:
Explanation:
• Segment 1: [1, 3, 5] (All positive)
• Segment 2: [-2, -6] (All negative)
• Segment 3: [8] (Positive)
Total segments = 3.
Problem Title: The Orchard Irrigation Project
Problem Statement
An orchard contains n trees. To ensure healthy growth, each tree is watered according to a
specific schedule. You are given:
1. A constant overhead volume of water m (used to prime the pump for each tree).
2. An array a of size n, where a[i] is the number of times the i-th tree is watered.
3. An array b of size n, where b[i] is the amount of water used in each watering session for
the i-th tree.
The total water consumed by the i-th tree is calculated using the formula:
Water[i] = m + (a[i] * b[i])
Your task is to calculate and return the total water used for all n trees combined.
Input Format
• The first line contains two integers: n (number of trees) and m (overhead constant).
• The second line contains n space-separated integers representing array a.
• The third line contains n space-separated integers representing array b.
Output Format
• Print a single integer representing the sum of water used for all trees.
Example Case
Input:
3 10
241
5 3 10
Output:
62
Step-by-Step Calculation:
• Tree 0: 10 + (2 * 5) = 20
• Tree 1: 10 + (4 * 3) = 22
• Tree 2: 10 + (1 * 10) = 20
• Total Sum: 20 + 22 + 20 = 62
Problem Title: Circular Digit Continuity
Problem Statement
You are given a string of digits. We define a sequence as continuous if every digit after the first is
exactly one greater than the digit preceding it, following a circular pattern.
Specifically, if the current digit is Di and the previous digit is Di-1, they are continuous if:
Di = (Di-1 + 1) mod 10
This means the digit following 9 must be 0 to be considered continuous.
Your task is to count the number of continuous partitions (segments) in the string. A "break"
occurs, and a new partition starts, whenever the continuity rule is violated.
Input Format
• A single string S consisting of digits ('0'-'9').
Output Format
• A single integer representing the number of continuous partitions found in the string.
Example Case
Input:
"123567901"
Output:
Explanation:
1. Segment 1: "123" (1 -> 2 -> 3 is continuous).
2. Break! The next digit is 5. Since (3 + 1) mod 10 = 4 and 4 !=5, a new partition starts.
3. Segment 2: "567" (5 ->6 $ -> 7 is continuous).
4. Break! The next digit is 9. Since (7 + 1) mod 10 = 8 and 8 !=9, a new partition starts.
5. Segment 3: "901" (9 -> 0 -> 1 is continuous because (9 + 1) mod 10 = 0).