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

Space Station Billing and Risk Evaluation

The document outlines twelve programming challenges involving various computational tasks, such as calculating energy bills, evaluating risk scores, transforming numbers, generating patterns, validating access codes, decoding frequencies, analyzing grids, and navigating paths. Each challenge specifies input formats, output requirements, constraints, and sample cases, emphasizing the use of primitive types, loops, and recursion without built-in functions or collections. The tasks range from simple calculations to complex algorithms, requiring careful implementation of specified rules.

Uploaded by

jindalmayank23
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)
9 views55 pages

Space Station Billing and Risk Evaluation

The document outlines twelve programming challenges involving various computational tasks, such as calculating energy bills, evaluating risk scores, transforming numbers, generating patterns, validating access codes, decoding frequencies, analyzing grids, and navigating paths. Each challenge specifies input formats, output requirements, constraints, and sample cases, emphasizing the use of primitive types, loops, and recursion without built-in functions or collections. The tasks range from simple calculations to complex algorithms, requiring careful implementation of specified rules.

Uploaded by

jindalmayank23
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

### Q1.

Galactic Energy Billing


**Description**
You work for a space-station that charges ships for docking based on how much energy they
consume.
The total bill is computed using a fixed mathematical formula that combines integers, doubles,
and multiple operators.
You must compute the final bill using only data types and operators (no loops, no if/else).
A ship provides:
- baseEnergy (double) – base energy units consumed
- peakMultiplier (int) – integer multiplier applied during peak hours
- serviceFee (double) – fixed additional fee
- discountPercent (int) – percentage discount on the energy part only (not on service fee)

The final bill is computed as:


1. Energy charge = baseEnergy * peakMultiplier
2. Discount on energy = Energy charge * (discountPercent / 100.0)
3. Discounted energy = Energy charge - Discount on energy
4. Final bill = Discounted energy + serviceFee

You must round the final bill to 2 decimal places using arithmetic only (no library methods).
Hint: To round a positive double x to 2 decimals:
rounded = (long)(x * 100 + 0.5) / 100.0;

**Input Format**
One line with four values: baseEnergy peakMultiplier serviceFee discountPercent
All values are space-separated. No multiple test cases.

**Output Format**
Print the final bill as a double, rounded to 2 decimal places.

**Constraints**
- 0.0 <= baseEnergy <= 1e6
- 1 <= peakMultiplier <= 100
- 0.0 <= serviceFee <= 1e5
- 0 <= discountPercent <= 90
- Use only primitive types and operators (arithmetic, relational, assignment, etc.).
- Do not use arrays, loops, if/else, or library rounding methods.

**Sample Input**
1500.0 3 250.0 10
**Sample Output**
4300.00
### Q2. Multi-Policy Risk Score Evaluator
**Description**
You are building a risk evaluation engine for an insurance company.
Each client’s risk score is calculated using integer and boolean flags, combined only with
operators (no loops, no if/else).
Each client gives:
- age (int)
- accidents (int) – number of accidents in last 5 years
- isSmoker (int) – 1 if smoker, 0 if not
- hasChronicDisease (int) – 1 if any chronic disease, 0 otherwise
- baseScore (int) – base risk score

The final riskScore is calculated using this formula:


1. ageFactor = (age / 10) (integer division)
2. accidentPenalty = accidents * 7
3. healthPenalty = (isSmoker * 15) + (hasChronicDisease * 20)
4. rawScore = baseScore + ageFactor + accidentPenalty + healthPenalty
5. Then apply a capping rule using a ternary operator:
- If rawScore > 100, finalScore = 100
- Else finalScore = rawScore

But you are NOT allowed to use if/else. You must use the ternary operator ? : to implement the
capping.

**Input Format**
One line with 5 integers: age accidents isSmoker hasChronicDisease baseScore

**Output Format**
Print a single integer: the final capped risk score.

**Constraints**
- 18 <= age <= 100
- 0 <= accidents <= 20
- isSmoker ∈ {0, 1}
- hasChronicDisease ∈ {0, 1}
- 0 <= baseScore <= 100
- Use only: primitive types (int, long, etc.), arithmetic, relational, logical, ternary, assignment
operators
- Do not use: if/else, loops, arrays, collections

**Sample Input**
35 2 1 0 40
**Sample Output**
72
### Q3. The Time-Warp Digit Transformer
**Problem Statement**
A mysterious device found in an ancient lab transforms a number by repeatedly reversing its
digits and adding the reversed value back to the original.
The process stops when the number becomes a palindrome (reads the same forward and
backward).
Your task is to simulate this transformation using loops and conditions only.
For each test case:
1. Take an integer N.
2. Reverse its digits using a loop.
3. Add the reversed number to the original number.
4. Repeat until the number becomes a palindrome.
5. Output the final palindrome and the total number of iterations performed.

Note:
- All operations must be done using loops and conditions — no in-built reverse methods.
- Input number will always reach a palindrome within the limits given.

**Input Format**
- First line: Integer T, number of test cases.
- Next T lines: Each contains an integer N.

**Output Format**
For each test case, print:
<palindrome> <iterations>

**Constraints**
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 10⁴
- Maximum 100 iterations allowed
- No string functions for reversing

**Sample Input**
3
89
56
7
**Sample Output**
881 2
121 1
70
### Q4. Pattern of the Shifting Triangles
**Problem Statement**
An encrypted manuscript contains a geometric pattern formed by repeatedly shifting triangular
blocks.
For each test case, you will be given N, and you must print a special triangle pattern using
nested loops.
The rules:
1. The triangle must have N rows.
2. Each row prints numbers starting from that row’s index up to N.
3. After printing the upper half, print the mirror lower half (excluding the middle row).
4. Final pattern must form a vertically symmetric hourglass shape.

**Input Format**
- First line: integer T, number of test cases
- For each test case: integer N

**Output Format**
Print the hourglass triangle pattern for each test case.
Patterns for separate test cases must be separated by a blank line.

**Constraints**
- 1 ≤ N ≤ 15
- No arrays required (loops only)

**Sample Input**
1
4
**Sample Output**
4321
432
43
4
43
432
4321
### Q5. Planetary Access Validator
**Problem Statement**
A space agency has multiple research stations, each requiring a unique access code based on
environmental conditions.
For each test case, you will read:
- Temperature (T)
- Radiation Level (R)
- Oxygen Percentage (O)

Using only conditions + operators, you must determine whether access is granted.
Access is GRANTED only if:
1. Temperature is between –50 and 60 (inclusive), AND
2. Radiation is below 300, AND
3. Oxygen level is between 19% and 23%, OR
4. Any reading is in emergency override range:
- T < –100 or T > 100
- R < 0 or R > 500
- O < 10 or O > 40

Outputs must be:


- "GRANTED"
- "DENIED"

**Input Format**
- First line: integer T, number of test cases
- Next T lines: three integers representing T R O

**Output Format**
For each test case, print one line: GRANTED or DENIED

**Constraints**
- 1 ≤ Test cases ≤ 100
- Use only loops, conditions, and operators
- No arrays beyond simple input storage

**Sample Input**
3
10 200 21
70 150 20
120 100 50
**Sample Output**
GRANTED
DENIED
GRANTED
### Q6. Archive Frequency Decoder
**Problem Statement**
You are working as a Data Curator in the Grand Interstellar Archive, a massive vault storing
numeric records collected from different planets.
Each transmission received by the archive contains a sequence of integers. However, the
archive must store only the unique values and also record how many times each value
appeared in the transmission.
The system you are programming is old and powerful — but it has strict rules:
- You cannot use HashMap, HashSet, Collections, or any built-in frequency functions.
- You must decode the frequency manually, using only: loops, primitive arrays, conditions

The archive demands:


- Print each unique value in the order it appeared in the transmission.
- Along with the count of its occurrences.

**Input Format**
- First line: Integer T — number of transmissions
- For each transmission:
- Integer N — number of records
- Next line: N space-separated integers

**Output Format**
For each transmission, print multiple lines in the format:
value frequency
Each test case’s output must appear exactly in the order the values first appeared.

**Constraints**
1 ≤ T ≤ 50
1 ≤ N ≤ 100000
0 ≤ record[i] ≤ 1000000
Only loops + primitive arrays allowed
No HashMap, HashSet, Collections, or built-in frequency methods

**Sample Input**
1
6
775957
**Sample Output**
73
52
91
### Q7. The Vault Grid Encryption Analyzer
**Problem Statement**
You are an apprentice engineer in the Titan Security Vault, a high-tech underground treasury
that protects rare minerals and ancient alien artifacts.
The vault floor is built as a 2D grid of compartments, where each cell stores a security activation
number.
Every day, the vault’s AI system requires a special security analysis:
You must determine the maximum activation value in each row, and then compute the sum of all
these row-wise maximums.
This process generates the Daily Encryption Strength Score, used to validate the vault’s
defense systems.
But there are restrictions:
- The vault AI only accepts manual array traversal.
- You cannot use: Collections, Streams, Built-in max functions, Matrix helper libraries

You must read the grid, find the max in each row using loops only, print all row-wise maximums,
and finally print their sum.

**Input Format**
- First line: integer T, number of vault scans
- For each test case:
- Two integers R and C (rows and columns)
- Next R lines: each containing C integers (the grid values)

**Output Format**
For each test case:
1. First print R integers → each row’s maximum value
On the next line, print:
Total = <sum_of_row_maximums>

**Constraints**
1 ≤ T ≤ 20
1 ≤ R, C ≤ 100
0 ≤ grid[i][j] ≤ 10^6
No inbuilt max(), no collections
Only loops + primitive arrays allowed

**Sample Input**
1
34
5193
8247
6666
**Sample Output**
986
Total = 23
### Q8. The Artifact Heat-Mapping Challenge
**Problem Statement**
You are working in the ArchaeoTech Research Lab, where scientists study mysterious alien
artifacts.
Each artifact is placed on a heat-sensitive analysis table, represented as a 2D grid.
Every cell of the grid records the heat intensity level detected at that point.
The lab wants to identify all “Peak Hotspots”, which are defined as:
A cell that is strictly greater than all of its four direct neighbors: Up, Down, Left, Right
(If a neighbor does not exist — e.g., edge or corner cell — ignore that side.)
Your task is to:
1. Analyze the heat grid
2. Detect every Peak Hotspot
3. Print their values from left to right, top to bottom
4. If no hotspots exist, print -1

You must use only primitive arrays and loops. No helper libraries, no collections, no matrix
functions.

**Input Format**
- First line: integer T, the number of heat-scans
- For each test case:
- Two integers R and C
- Next R lines: each containing C integers (heat levels)

**Output Format**
For each test case:
- Print all hotspot values separated by a space
- If none found, print -1
- After each test case, print a new line

**Constraints**
1 ≤ T ≤ 20
1 ≤ R, C ≤ 100
0 ≤ heat[i][j] ≤ 10^6
Hotspot: heat[i][j] > all existing neighbors
Loops only, no collections

**Sample Input**
1
33
534
192
637
**Sample Output**
597
### Q9. The Security Grid Rotation Protocol
**Problem Statement**
You are assisting the Interstellar Security Division (ISD) in managing the surveillance system of
a high-tech space vault.
The vault’s camera feeds are arranged in a square 2D matrix, where each cell represents the ID
of a camera tile.
Whenever the vault enters LOCKDOWN MODE, the entire security grid must rotate 90 degrees
clockwise instantly.
Your task is to perform this rotation manually using only 2D arrays and loops, with no built-in
matrix functions.
Your mission: Given an N × N camera grid, rotate it 90° clockwise in-place (using only arrays, no
extra collection framework), and print the updated security grid.

**Important Rules**
You MUST:
1. Only use primitive 2D arrays
2. Use nested loops
3. Avoid Java built-in matrix rotation utilities
4. Print rows exactly as they appear after rotation

**Input Format**
- First line: integer T, number of test cases
- For each test case:
- One integer N
- Next N lines: each containing N integers

**Output Format**
For each rotated matrix:
- Print N lines
- Each containing N space-separated integers
- After each test case, print a new line

**Constraints**
1 ≤ T ≤ 20
1 ≤ N ≤ 100
0 ≤ grid[i][j] ≤ 10^6
Rotation = 90° clockwise

**Sample Input**
1
3
123
456
789
**Sample Output**
741
852
963
### Q10. The Artifact Heat Map Analyzer
**Problem Statement**
You are part of an elite archaeology research team exploring the ruins of an ancient civilization.
The excavation site is mapped as a 2D grid, where each cell stores the heat signature of an
artifact fragment buried underground.
However, the ancient scanners are unstable — they can only detect artifacts if they are part of a
“hot zone cluster.”
A hot zone cluster is defined as a row whose sum of elements is strictly greater than every other
row in the grid.
Your task: Find the row with the highest sum of heat values.
If multiple rows tie for the highest sum, select the first such row.
You must print:
- The row index (0-based)
- The maximum sum
- The entire row after identifying it

This must be implemented using:


- Only primitive 2D arrays
- Nested loops
- No built-in functions like [Link](), list structures, or collections

**Input Format**
- First line: integer T, number of test cases
- For each test case:
- Integer N → number of rows
- Integer M → number of columns
- Next N lines → each containing M integers

**Output Format**
For each test case:
Print:
RowIndex MaxSum
<row elements>
Leave one blank line after each test case

**Constraints**
1 ≤ T ≤ 20
1 ≤ N, M ≤ 200
0 ≤ grid[i][j] ≤ 10^6

**Sample Input**
1
34
1234
9111
5521
**Sample Output**
2 13
5521
### Q11. The Portal Depth Counter
**Problem Statement**
You are exploring an alien world where energy portals appear in nested layers.
A portal’s blueprint is represented as an array:
- Positive number → energy value
- 0 → indicates a new inner portal begins
- -1 → indicates closure of the most inner portal

Your task is to calculate the maximum depth of nested portals using recursion only.
You must write a recursive function:
int max maxDepth(int arr[], int index, int currentDepth)

**Rules**
- Every time you encounter 0, depth increases
- Every time you encounter -1, depth decreases
- You must track the highest value of currentDepth
- No loops allowed — recursion only.

**Input Format**
- T → number of test cases
- For each test case:
- N → number of elements
- Next N space-separated integers

**Output Format**
Print maximum depth for each test case.

**Constraints**
1 ≤ T ≤ 50
1 ≤ N ≤ 10⁵
Array elements ∈ {0, -1} ∪ positive integers
Recursion depth ≤ 10⁵

**Sample Input**
1
7
5 0 4 0 3 -1 -1
**Sample Output**
2
### Q12. The Forbidden Path Navigator
**Problem Statement**
You are traversing a fragile floating bridge made of tiles.
You start at tile 1 and must reach tile N.
Movement Rules:
- From any tile i, you can jump:
- 1 step forward
- 2 steps forward

Write a recursive function:


int countWays(int n)
that returns number of distinct ways to reach tile N.
This is the classic stair-climbing recursion — but themed for your exam.
- Use recursion only
- No loops, no DP, no arrays.

**Input Format**
- T test cases
- Each test case: single integer N

**Output Format**
Print number of ways for each test case.

**Constraints**
1 ≤ T ≤ 50
1 ≤ N ≤ 30

**Sample Input**
1
4
**Sample Output**
5
### Q13. The Mirror Message Generator
**Problem Statement**
A secret rebel base communicates using mirror messages.
A message is valid only when its characters are reversed.
You must write a recursive function:
String reverse(String s, int index)
that returns the reverse of the string.

**Rules**
- No loops allowed
- No built-in reverse methods
- No extra arrays/lists allowed
- Only recursive calls + charAt()

**Input Format**
- T test cases
- Each test case: one string S

**Output Format**
Print reversed string for each test case.

**Constraints**
1 ≤ T ≤ 50
1 ≤ |S| ≤ 1000
Characters can be alphabetic or digits

**Sample Input**
1
STAR
**Sample Output**
RATS
### Q14. The Cipher Shift Analyzer
**Problem Statement**
In a classified government research lab, messages are encrypted using a shifting cipher.
The encryption works like this:
For a given secret message S, each character is shifted forward in the alphabet by its index
value (0-based).
You are part of the decryption unit — your job is to decode the message by reversing this shift.

**Rules**
- You must shift backward by the index value.
- Only lowercase letters (‘a’–‘z’) are guaranteed.
- If shifting backward crosses ‘a’, it wraps around from ‘z’.

**Input Format**
- First line: integer T (test cases)
- Next T lines: a lowercase string S

**Output Format**
For each test case, print the decoded string.

**Constraints**
- 1 ≤ T ≤ 50
- 1 ≤ |S| ≤ 10⁵
- Total input length ≤ 5×10⁵
- No use of built-in rotate/shift functions.

**Sample Input**
2
dgh
bdfh
**Sample Output**
dff
azej
### Q15. The Forbidden Words Detector
**Problem Statement**
A digital library filters user comments for banned words.
You are assigned to build a detector that can:
1. Count how many times a banned word appears
2. Detect if any occurrence overlaps with another
3. Do this without using contains(), indexOf(), or substring slicing

Your job: manually compare character by character.

**Input Format**
- First line: T
- For each test case:
- Line 1 → Comment string
- Line 2 → Banned word

**Output Format**
Print <count> <overlapFlag>
- overlapFlag = YES if any overlaps exist
- otherwise NO

**Constraints**
- Case sensitive search
- 1 ≤ |Comment|, |Word| ≤ 10⁵

**Sample Input**
1
aaaa
aa
**Sample Output**
3 YES
### Q16. The Mirror-Palace Validator
**Problem Statement**
In an ancient palace, inscriptions must satisfy two magical conditions to be considered valid:
1. After removing spaces, the text must read the same forward and backward (palindrome).
2. The text must contain at least one vowel (a, e, i, o, u).

If both conditions are met → "VALID"


Otherwise → "INVALID"
Case-insensitive check.

**Input Format**
- First line: T
- Next T lines: each contains a string (may contain spaces)

**Output Format**
Print "VALID" or "INVALID".

**Constraints**
- 1 ≤ |S| ≤ 10⁵
- At least one non-space character guaranteed

**Sample Input**
1
nurses run
**Sample Output**
VALID
### Q17. The Frequency Forge
**Problem Statement**
A magical spell scroll contains a long sequence of characters.
The wizard needs a frequency report showing how many times each ASCII character occurs.
You must count frequencies using only:
- A fixed integer array freq[256]
- Loops
- No HashMap, no Collections

Finally, print each character and its count in ASCII order, but only those with frequency > 0.

**Input**
One string S (may contain any ASCII characters)

**Output**
<char>:<count>
each on a new line

**Constraints**
- 1 ≤ |S| ≤ 10⁵
- ASCII only

**Sample Input**
abbca
**Sample Output**
a:2
b:2
c:1
### Q18. The Pattern Extractor
**Problem Statement**
A planetary archive stores mixed-format identifiers that contain:
- Lowercase letters
- Uppercase letters
- Digits

Your task:
Extract two sequences:
1. The sequence of all letters in order
2. The sequence of all digits in order

Then return the combined result: <letters><digits>

**Input Format**
One string S

**Output Format**
One string

**Constraints**
1 ≤ |S| ≤ 10⁵
No arrays except for building output

**Sample Input**
a1b2c9
**Sample Output**
abc129
### Q19. Galactic Drone Registration System
**Problem Statement**
In a futuristic space city, thousands of drones operate daily for delivery, surveillance, and
maintenance.
Every drone must be registered before it is allowed to fly in the city.
You must design a class Drone that stores the registration details of every drone.
Each drone has:
- String id – unique drone ID
- String model – model name
- int batteryLevel – battery percentage
- boolean isArmed – whether drone carries security equipment

You must implement:


**Constructors**
1. Default constructor: id = "UNKNOWN", model = "BASIC", batteryLevel = 0, isArmed = false
2. Parametrized constructor (id, model): batteryLevel = 100, isArmed = false
3. Fully parametrized constructor (id, model, batteryLevel, isArmed)

**Methods**
1. void updateBattery(int newLevel)
2. void authorizeSecurity(boolean flag)
3. String toString(): Drone[ID=<id>, Model=<model>, Battery=<batteryLevel>%,
Armed=<true/false>]

**Input Format**
- First line → integer T, number of test cases
- For each test case: (format varies by constructor and actions)

**Output Format**
Print the object using toString().

**Sample Input**
1
2
DRN11 Falcon
1
75
**Sample Output**
Drone[ID=DRN11, Model=Falcon, Battery=75%, Armed=false]
### Q20. Underwater Habitat Sensor System
**Problem Statement**
A deep-sea research center monitors its underwater habitats using smart sensors.
Create a class Sensor that stores:
- String location
- double temperature
- double pressure
- boolean isFaulty

**Constructors**
1. Default: location = "UNKNOWN", temperature = 0.0, pressure = 0.0, isFaulty = false
2. Constructor(location, temperature): pressure = 1.0, isFaulty = false
3. Fully parameterized

**Methods**
1. void updateTemperature(double t)
2. void updatePressure(double p)
3. void markFault(boolean f)
4. String toString(): Sensor[Location=<location>, Temp=<temperature>, Pressure=<pressure>,
Fault=<true/false>]

**Input / Output Format**


Same pattern as previous class-based questions.

**Sample Input**
1
2
ModuleA 12.6
1
15.9
**Sample Output**
Sensor[Location=ModuleA, Temp=15.9, Pressure=1.0, Fault=false]
### Q21. Smart City Vehicle Pass Generator
**Problem Statement**
In a smart city, vehicles must carry digital passes to access restricted zones.
You must design a class VehiclePass to generate these passes.

**Data Members**
- String owner
- String vehicleType
- int passLevel
- boolean ecoCertified

**Constructors**
1. Default constructor: owner = "NA", vehicleType = "UNKNOWN", passLevel = 0, ecoCertified =
false
2. Constructor(owner, vehicleType): passLevel = 1, ecoCertified = false
3. Constructor(owner, vehicleType, passLevel, ecoCertified)

**Methods**
1. void upgradeLevel(int newLevel)
2. void updateEco(boolean flag)
3. toString(): Pass[Owner=<owner>, Type=<vehicleType>, Level=<passLevel>,
Eco=<true/false>]

**Sample Input**
1
2
Amit Car
1
3
**Sample Output**
Pass[Owner=Amit, Type=Car, Level=3, Eco=false]
### Q22. Solar Grid Consumption Tracker
**Problem Statement**
You are working at a futuristic energy station that supplies power to houses connected through a
solar grid.
Each house consumes a certain number of energy units per day.
But on weekends, the Solar Council offers discounted rates.
Design a class SolarGrid that tracks a single household’s consumption and calculates the final
payable amount.

**Data Members (Private)**


- String houseID
- double unitRate (rate per unit)
- int unitsConsumed
- int weekendDiscount (percentage discount on total bill)

**Constructors**
1. Default constructor: houseID = "NA", unitRate = 0.0, unitsConsumed = 0, weekendDiscount =
0
2. Parameterized constructor (houseID, unitRate): unitsConsumed = 0, weekendDiscount = 0
3. Full constructor (houseID, unitRate, unitsConsumed, weekendDiscount)

**Methods**
double calculateBill()
total = unitRate * unitsConsumed
discount = total * weekendDiscount / 100.0
finalAmount = total - discount
return finalAmount

**Sample Input**
2
H109 15.5
**Sample Output**
SolarGrid[ID=H109, Units=0, Final=0.0]
### Q23. Creature Passport Registry
**Problem Statement**
In an interplanetary wildlife program, each alien creature must be issued a Creature Passport
for tracking and migration approvals.
Create a class CreaturePassport with details about each creature.

**Data Members**
- String name
- int age
- String species
- double healthScore

**Constructors**
1. Default: name="Unknown", age=0, species="NA", healthScore=0.0
2. Parameterized (name, age): species="NA", healthScore=50.0
3. Full (name, age, species, healthScore)

**Methods**
void updateSpecies(String sp)
void updateHealth(double score)

**Sample Input**
2
Zork 12
2
Reptiloid 88.5
**Sample Output**
Passport[Name=Zork, Species=Reptiloid, Health=88.5]
### Q24. AstroWallet – Space Credit Manager
**Problem Statement**
In a galaxy-wide trading federation, every trader holds an AstroWallet, which stores their space
credits.
You must develop the AstroWallet class.

**Data Members**
- String ownerName
- long credits (balance)
- String walletID

**Constructors**
1. Default: ownerName="NA", credits=0, walletID="NONE"
2. Parameterized(ownerName, walletID): credits=0
3. Full(ownerName, walletID, credits)

**Methods**
void addCredits(long amount)
void deductCredits(long amount)

**Sample Input**
2
Aiden W202
1
500
**Sample Output**
Wallet[Owner=Aiden, Credits=500, ID=W202]
### Q25. Drone Configuration Module
**Problem Statement**
You are working in an elite robotics research center where drones are prepared for various
missions.
Each drone has its own model identity, version, battery type, and a set of upgradeable modules.
The drone is represented through a class DroneConfig, and your task is to implement this class
using constructor overloading and method overloading.
A drone has 5 configurable modules stored in the following fixed order:
["Camera", "Propeller", "GPS", "Frame", "Sensor"]

**Class Requirements**
**Private Data Members**
- String modelCode
- int versionNumber
- String batteryType
- String[] modules (size = 5)

**Constructors**
1. Default Constructor: modelCode = "UNASSIGNED", versionNumber = 0, batteryType =
"UNKNOWN", modules = [null, null, null, null, null]
2. Parameterized Constructor: DroneConfig(int versionNumber, String batteryType)
3. Fully Parameterized Constructor: DroneConfig(String modelCode, int versionNumber, String
batteryType, String[] modules)

**Method Overloading: updateModule()**


1. updateModule(String propeller) → modules[1] = propeller
2. updateModule(String camera, String gps) → modules[0] = camera, modules[2] = gps
3. updateModule(String sensor, String frame, String camera) → modules[4] = sensor,
modules[3] = frame, modules[0] = camera

**Input Format**
Two integers in sequence:
First Integer → Constructor Selection (0, 2, 4)
Second Integer → updateModule() Selection (0, 1, 2, 3)

**Output Format**
Print:
DroneConfig[ Model = <modelCode> Modules = [m1, m2, m3, m4, m5] ]

**Sample Input**
0
1
UltraProp
**Sample Output**
DroneConfig[ Model = UNASSIGNED Modules = [null, UltraProp, null, null, null] ]
### Q26. Wildlife Animal Tracker
**Problem Statement**
You have been hired by the National Wildlife Research Center (NWRC) to build a tracking
module for their animal monitoring system.
Each animal that enters a protected zone must be registered with:
- Species name (String)
- Age (int, in years)
- Weight (int, in kilograms)
- Zone number (int, which protected zone the animal is currently in)

**Class Requirements**
**Constructor**
public Animal(String species, int age, int weight, int zone)

**Getter Methods**
public String getSpecies()
public int getAge()
public int getWeight()
public int getZone()

**Input Format**
- First line: Integer T (number of test cases)
- For each test case: Four space-separated values: species age weight zone

**Output Format**
For each test case, print the String returned by toString().

**Sample Input**
2
Tiger 5 220 12
Elephant 40 3500 3
**Sample Output**
Animal[species=Tiger, age=5, weight=220, zone=12]
Animal[species=Elephant, age=40, weight=3500, zone=3]
### Q27. Space Cargo Weight Manager
**Problem Statement**
You are working as a cargo engineer on an interplanetary transport ship.
Every shipment sent to space is packed inside a cargo container box with three dimensions:
length (int), width (int), height (int).
Your task is to design a class CargoBox that helps the ship’s system track and calculate the
space occupied by each container.

**Class Requirements**
1. Default Constructor: public CargoBox() → all dimensions 0
2. Parameterized Constructor: public CargoBox(int length, int width, int height)
3. Copy Constructor: public CargoBox(CargoBox other)
4. Getter Methods for length, width, height
5. public long calculateVolume() → length * width * height

**Input Format**
- First line: Three integers → dimensions for first box
- Second line: Three integers → dimensions for second box

**Output Format**
Print dimensions and volume for:
1. Default box
2. First parameterized box
3. Copy of the first box
Each in format: length width height volume

**Sample Input**
345
789
**Sample Output**
0000
3 4 5 60
3 4 5 60
### Q28. Treasure Map Editor – Swap Two Markers
**Problem Statement**
You are working for an archaeological team maintaining a digital treasure map.
Each location on the map is represented as a node in a doubly linked list, where each node
stores a unique marker ID.
A mapping mistake has swapped the positions of two treasure markers.
You are given two positions A and B, and your task is to swap the nodes present at these
positions.
You must swap the nodes themselves, not just values, while keeping all other node connections
intact.
If either position is invalid, no swap should be performed.

**Input Format**
- First line: Integer N — number of markers
- Second line: N space-separated integers representing marker IDs
- Third line: Two integers A and B (1-based positions to swap)

**Output Format**
Print the updated list of marker IDs after swapping.

**Constraints**
- 1 ≤ N ≤ 10⁵
- Marker IDs: 1 ≤ value ≤ 10⁹
- Positions: 1 ≤ A, B ≤ 10⁵
- Must swap nodes in a doubly linked list
- Time complexity expected: O(N)

**Sample Input**
6
10 20 30 40 50 60
25
**Sample Output**
10 50 30 40 20 60
### Q29. Galactic Shuttle Line Reordering
**Problem Statement**
In a futuristic interplanetary spaceport, shuttles queue up in a line represented by a doubly
linked list.
A cosmic meteor shower alert forces the control center to rearrange the docking queue.
The directive states: Rotate the entire shuttle line to the RIGHT by K positions.
If K > N, rotate using K % N.
Perform the rotation by manipulating the DLL links only.

**Input Format**
- First line: Integer N — number of shuttles
- Second line: N space-separated shuttle IDs
- Third line: Integer K — number of right rotations

**Output Format**
Print the updated shuttle order after rotation.

**Constraints**
- 1 ≤ N ≤ 10⁵
- 0 ≤ K ≤ 10⁹
- Time complexity expected: O(N)

**Sample Input**
5
79316
2
**Sample Output**
16793
### Q30. The Archive Scroll Keeper – Remove Last Record
**Problem Statement**
You are the custodian of an ancient digital archive scroll, where each historical record is linked
using a doubly linked list.
The final record was incorrectly added and must be removed.
Delete the last node and ensure the second-last node becomes the new end.
If only one record, deletion results in an empty list.

**Input Format**
- First line: Integer N — number of records
- Second line: N space-separated integers (record IDs)

**Output Format**
Print all remaining record IDs after removing the last one.
If the list becomes empty, print nothing.

**Constraints**
- 0 ≤ N ≤ 10⁵

**Sample Input**
4
12 45 33 90
**Sample Output**
12 45 33
### Q31. Solar Relay Beacon Counter
**Problem Statement**
A research vessel deploys a chain of solar energy relays in deep space.
These relays are connected in a perfect circular linked list, where:
- The last relay points back to the first relay
- There is no termination point

Your mission: Starting from the head relay, count the total number of relays in the circular chain.
You must stop exactly when you return to the starting relay.

**Input Format**
- First line: Integer N — number of relays
- Second line: N space-separated relay IDs

(You may assume the relays are already linked circularly.)

**Output Format**
Print a single integer — the total count of relays.

**Constraints**
- 1 ≤ N ≤ 10⁶
- Relay IDs: 1 ≤ value ≤ 10⁹
- Must traverse the circular list exactly once
- No extra arrays or collections allowed
- Time complexity: O(N)

**Sample Input**
3
5 9 11
**Sample Output**
3
### Q32. The Lost Signal Node in the Drone Relay Chain
**Problem Statement**
A fleet of surveillance drones communicates in a sequence — each drone forwards a signal to
the next one using a linked list connection:
Drone1 → Drone2 → Drone3 → … → DroneN
However, the final drone has a special authorization: It may choose to forward its signal to any
previous drone in the sequence, creating a loop for secret continuous surveillance.
The drone that receives two incoming signals (one from its predecessor, one from the last
drone) is called the Lost Signal Node.
Your task is to find that drone.
You are given a linked list of drone names and an integer P:
- If P = -1, the last drone does not connect back → no special drone → output -1
- Otherwise, the last drone forwards to the drone at position P (0-based)

**Input Format**
- First line: T — number of test cases
- For each test case:
1. Integer N — number of drones
2. N drone names
3. Integer P — index of special receiving drone or -1

**Output Format**
Print the name of the lost signal node. If no such node exists, print -1.

**Constraints**
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 10⁵
- Drone names are non-empty strings without spaces
- -1 ≤ P < N
- Total nodes across all test cases ≤ 10⁶
- Must run in O(N) per test case
- No collections like HashMap, HashSet
- No Floyd cycle detection — you have the index, just access directly

**Sample Input**
1
5
Alpha Beta Gamma Delta Echo
2
**Sample Output**
Gamma
### Q33. The Mutation Sequence Alternator
**Problem Statement**
A gene research lab stores mutation samples in a long sequence using a singly linked list.
To simulate alternating mutation waves, the lab follows this rule:
Reverse the first K samples, skip the next K samples, reverse the next K, skip the next K, and
so on.
This pattern continues until the list ends.
Your task is to perform this alternating mutation transformation.

**Input Format**
- First line: N — number of mutation samples
- Second line: N integers representing mutation markers
- Third line: K — block size for reversing alternate segments

**Output Format**
Print the resulting sequence after alternate K-block reversal.

**Constraints**
- 1 ≤ N ≤ 10⁵
-1≤K≤N
- Mutation marker values: 1 ≤ value ≤ 10⁹
- Must run in O(N)
- No arrays or collections to store the entire modified list; only pointer manipulation
- Recursion allowed if optimized; iterative solution recommended

**Sample Input**
8
10 20 30 40 50 60 70 80
3
**Sample Output**
30 20 10 40 50 60 80 70
### Q34. The Time Capsule Reordering Mission
**Problem Statement**
A research team stores ancient artifacts inside a time capsule chain, implemented as a singly
linked list.
Each artifact has a timestamp value (integer). Before sealing the capsule, the archivists impose
a rule:
All artifacts with even timestamps must appear before all artifacts with odd timestamps — while
keeping their original order within each group.
Your task is to reorganize the list following this rule and return the new head.

**Input Format**
- Integer T — number of test cases
- For each test case:
1. Integer N — number of artifacts
2. N integers — timestamps

**Output Format**
Print the reordered list values.

**Constraints**
- 1 ≤ T ≤ 50
- 0 ≤ N ≤ 10⁵
- Timestamp values: 0 ≤ value ≤ 10⁹
- Must maintain stable ordering
- Must run in O(N)

**Sample Input**
1
7
5 2 9 8 11 4 7
**Sample Output**
2 8 4 5 9 11 7
### Q35. The Quantum Train Compartment Merger
**Problem Statement**
A futuristic train stores passenger groups in two separate linked lists:
- List A = priority passengers
- List B = normal passengers

A new boarding rule requires merging both lists in an alternating pattern:


Take one node from List A → then one from List B → then from A → then B...
If one list ends early, append the remaining nodes of the other list to the end.
Your task is to merge the two lists into one in this alternating manner.

**Input Format**
- First line: T test cases
- For each test case:
1. Integer N1 — size of list A
2. N1 integers for list A
3. Integer N2 — size of list B
4. N2 integers for list B

**Output Format**
Print the merged linked list.

**Constraints**
- 1 ≤ T ≤ 50
- 0 ≤ N1, N2 ≤ 10⁵
- Node values: 1 ≤ value ≤ 10⁹
- Must run in O(N1 + N2)
- No new data structures except pointers

**Sample Input**
1
3
10 20 30
4
7 8 9 10
**Sample Output**
10 7 20 8 30 9 10
### Q36. The Galactic Debris Filter
**Problem Statement**
A cleanup robot roams through a galaxy, collecting space debris represented as nodes in a
linked list.
Some debris pieces are too small (value < 50) and should be removed.
Your task: Remove all nodes with value < 50 from the linked list and return the new head.
If all items are removed, output -1.

**Input Format**
- Integer N — number of debris items
- N integers — debris sizes

**Output Format**
Print the remaining list or -1 if empty.

**Constraints**
- 0 ≤ N ≤ 10⁵
- Node values: 0 ≤ debris size ≤ 10⁹
- Must run in O(N)

**Sample Input**
6
10 55 42 90 12 77
**Sample Output**
55 90 77
### Q37. The Memory Lane Reverse Walk
**Problem Statement**
A historian travels down a memory lane, represented as a linked list of events.
They want to recall the memories in reverse order.
Your task: Reverse the entire linked list and return the new head.

**Input Format**
- Integer N — number of events
- N integers — event IDs

**Output Format**
Print the reversed list.

**Constraints**
- 0 ≤ N ≤ 10⁵
- Must run in O(N) time and O(1) extra space

**Sample Input**
5
12345
**Sample Output**
54321
### Q38. The Time Capsule ID Verifier
**Problem Statement**
You are working in a futuristic museum where ancient civilizations stored messages inside time
capsules.
Each capsule has an ID string engraved on it. A capsule is considered authentic only if its ID
reads the same forward and backward.
To verify authenticity, the museum rules require you to check the ID using a stack-based
reversal method (no built-in reverse functions allowed).

**Your Task**
Implement: boolean isAuthentic(String id)
Return true if the ID is a palindrome, otherwise return false.

**Input Format**
- First line: integer T, number of capsules
- Next T lines: a string ID (may contain letters/digits)

**Output Format**
For each ID print: Authentic or Fake

**Constraints**
- 1 ≤ T ≤ 100
- 1 ≤ |ID| ≤ 1000
- Only letters and digits allowed
- Must use a stack explicitly

**Sample Input**
3
MALAYALAM
A12321A
STAR123
**Sample Output**
Authentic
Authentic
Fake
### Q39. Spell Reversal for the Wizard’s Grimoire
**Problem Statement**
A powerful wizard keeps magical spells written in his grimoire.
Before casting, every spell must be reversed to activate its arcane energy.
The wizard insists that the reversal must be done using a stack, not using built-in string
methods.

**Your Task**
Implement: String reverseSpell(String spell)
The function must:
- Push each character onto a stack
- Pop characters to form the reversed spell

**Input Format**
- First line: integer T, number of spells
- Next T lines: each containing a spell string

**Output Format**
For each spell, print its reversed form on a new line.

**Constraints**
- 1 ≤ T ≤ 100
- 1 ≤ |spell| ≤ 10⁵
- Only stack operations allowed
- No built-in reverse methods

**Sample Input**
2
abra
MAGIC
**Sample Output**
arba
CIGAM
### Q40. The Library Book Reordering Machine
**Problem Statement**
A digital library has a machine that rearranges a batch of returned books.
Books arrive in a queue, but due to a mechanical rule, before shelving them, the machine
reverses their order using a stack.
Your task is to simulate this reordering.

**Your Task**
Implement: void reorder(int[] books)
The function must:
- Dequeue all books
- Push them into a stack
- Pop from the stack and enqueue them back
- Resulting order becomes reversed

**Input Format**
- First line: integer T (test cases)
- For each test case:
- First line: N, number of books
- Next line: N integers representing book IDs (initial queue order)

**Output Format**
Print the reversed sequence of book IDs.

**Constraints**
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 10⁵
- Book IDs are integers
- Must use one queue + one stack

**Sample Input**
1
5
10 20 30 40 50
**Sample Output**
50 40 30 20 10
### Q41. The Ancient Spell Scroll Validator
**Problem Statement**
You discover an old scroll containing magical spells written with special rune brackets:
- { } Shield Runes
- ( ) Mind Runes
- [ ] Binding Runes

A spell is valid only if:


- Every opening rune has a correct matching closing rune
- Runes close in the proper order
- No mismatched or unbalanced symbols exist

This must be checked using a stack, as the ancients intended.

**Your Task**
Implement: boolean validateScroll(String spell)
Return:
- Valid if brackets are balanced
- Invalid otherwise

**Input Format**
- First line: integer T
- Next T lines: spell strings (may include letters and bracket runes)

**Output Format**
One line per test case: Valid or Invalid

**Constraints**
- 1 ≤ T ≤ 100
- 1 ≤ |spell| ≤ 10⁵
- Only the characters { } ( ) [ ] affect balance
- Must use a stack

**Sample Input**
3
{(a+b)}
([)]
spell{power[energy()]}
**Sample Output**
Valid
Invalid
Valid
### Q42. The Time Capsule Queue Reversal
**Problem Statement**
You are a historian working in a futuristic museum where old artifacts are stored inside a Time
Capsule Queue.
Artifacts are inserted into the capsule in the exact order they arrive.
However, a malfunction has scrambled the temporal sequence, and you must reverse the entire
order of artifacts so the most recently added item appears first.
You are given a queue representing the arrival order of the artifacts.
Your task is to reverse the queue completely using standard queue and stack operations.
Write the function: void reverseCapsule(int q[])

**Input Format**
- First line: Integer T, number of test cases
- For each test case:
- Integer N — number of artifacts
- Next line: N space-separated integers representing artifacts in arrival order

**Output Format**
For each test case, print the reversed queue elements in a single line, space-separated.

**Constraints**
- 1 ≤ T ≤ 100
- 0 ≤ N ≤ 10⁵
- –10⁹ ≤ artifact values ≤ 10⁹
- Use only stack + queue logic (no library reversal)
- Must run in O(N) per test case

**Sample Input**
1
4
10 20 30 40
**Sample Output**
40 30 20 10
### Q43. The Priority Checkpoint Rotation
**Problem Statement**
At an interplanetary security checkpoint, travelers form a queue for inspection.
However, the first K travelers must undergo a special scanning process that reverses their order,
while the rest of the queue must remain unchanged.
You are given:
- A queue representing traveler IDs
- An integer K, the number of travelers to reverse

Your task is to implement: void reverseFirstK(int q[], int K)


which reverses only the first K elements of the queue and leaves the remaining elements
untouched.

**Input Format**
- First line: Integer T, number of test cases
- For each test case:
- Integer N — number of travelers
- Next line: N integers representing traveler IDs
- Integer K

**Output Format**
Print the updated queue after reversing the first K IDs.

**Constraints**
- 1 ≤ T ≤ 100
- 0 ≤ N ≤ 10⁵
-1≤K≤N
- Traveler ID range: 1–10⁹
- Must use queue + stack operations only
- Time complexity: O(N)

**Sample Input**
1
5
7 14 21 28 35
3
**Sample Output**
21 14 7 28 35
### Q44. The Airport Runway Scheduler
**Problem Statement**
Every plane waiting for takeoff is placed in a queue based on arrival order.
However, due to sudden weather changes, all planes with priority level below a threshold P
must be moved to the front of the queue while maintaining their original relative order.
Planes with priority ≥ P must remain at the back, also in their original order.
You must rearrange the queue using only queue operations (no sorting, no arrays reordering).
Each plane is represented by an integer priority.
Write the function: void rearrangeRunway(int q[], int P)

**Input Format**
- First line: integer T
- For each test case:
- Integer N
- Next line: N integers (priority levels)
- Integer P — threshold priority

**Output Format**
Print the queue after rearrangement.

**Constraints**
- 1 ≤ T ≤ 100
- 0 ≤ N ≤ 200000
- Priority values: 0 ≤ value ≤ 10⁶
- Must maintain relative stability
- O(N) solution required

**Sample Input**
1
6
528173
4
**Sample Output**
213587
### Q45. Task Queue Time Estimator
**Problem Statement**
You are given a queue of tasks where each integer represents the time required to complete a
task.
The system executes tasks in order, but if a task takes more than X time, it is sent to the back of
the queue to be retried later.
This retry happens only once for each task, meaning:
- If a task > X on first encounter → move to back
- If it appears again → it must be executed and removed

Simulate this behavior using queue operations.


Implement: void processTasks(int q[], int X)

**Input Format**
- First line: T
- For each test case:
- Integer N
- Next line: N integers (task times)
- Integer X

**Output Format**
Print the final order of tasks after all have been executed.

**Constraints**
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 10⁵
- 0 ≤ task time ≤ 10⁹
- O(N) solution
- Use queue only

**Sample Input**
1
5
8 3 12 4 15
10
**Sample Output**
3 4 8 12 15
### Q46. Customer Window Distribution
**Problem Statement**
A bank has M service windows.
Customers enter a main queue, but each customer must be assigned to one of the windows in a
round-robin manner:
1st customer → Window 1
2nd customer → Window 2

Mth customer → Window M
(M+1)th → Window 1 again
You must distribute customers from the queue into M separate queues representing each
service window.
Write: void distributeCustomers(int q[], int M)

**Input Format**
- First line: T
- For each test case:
- Integer N
- Next line: N customer IDs
- Integer M — number of service windows

**Output Format**
Print M lines.
Each line = customers assigned to that window, in order.

**Constraints**
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 10⁵
- 1 ≤ M ≤ 20
- Customer IDs: 1–10⁹

**Sample Input**
1
7
11 22 33 44 55 66 77
3
**Sample Output**
11 44 77
22 55
33 66

This completes the full list of questions in the cleaned, properly numbered format.

You might also like