0% found this document useful (0 votes)
3 views5 pages

Lab 4

The document outlines a lab exam focused on algorithm design and analysis, featuring two main questions. The first question involves rearranging symbols according to specific rules to unlock a treasure in El Dorado, while the second question requires finding the minimum energy path through a grid maze. Each question has defined constraints and examples to illustrate the requirements.

Uploaded by

ABHISHEK BUDDIGA
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)
3 views5 pages

Lab 4

The document outlines a lab exam focused on algorithm design and analysis, featuring two main questions. The first question involves rearranging symbols according to specific rules to unlock a treasure in El Dorado, while the second question requires finding the minimum energy path through a grid maze. Each question has defined constraints and examples to illustrate the requirements.

Uploaded by

ABHISHEK BUDDIGA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Design and Analysis of

Algorithms


Lab Exam -4

Dr. Priodyuti Pradhan​


29-03-2025
Question 1:

The Lost Cipher of El Dorado [ 60 Marks]

Deep within the fabled city of El Dorado, hidden among golden temples and ancient relics, lies a
sacred cipher—the key to untold riches and power. Legend has it that only those who can
correctly rearrange its symbols may unlock the city’s greatest treasure. However, the cipher is
protected by two ancient traps, designed to keep unworthy explorers at bay.

You, a daring adventurer, have stumbled upon the cipher. Now, you must rearrange its letters
while obeying the rules of the Golden Code to claim the hidden treasure.

The Golden Code

1.​ The Curse of Greed (k) {20 Marks}​

○​ No two identical symbols can be placed less than k positions apart.​

○​ If the same symbol appears too close together, the cipher will activate a deadly
trap, sealing El Dorado forever.​

2.​ The Mirror of Illusions (L) {40 Marks}​

○​ No segment of exactly L symbols can form a palindrome.​

○​ If any sequence reads the same forward and backward, the illusion of El Dorado
will break, and the treasure will vanish into thin air.

Your Mission

If you can successfully rearrange the symbols while obeying these two rules, the golden vaults
will open before you.​
If it is impossible, return an empty response (""), signifying that El Dorado’s riches will remain
lost forever.
Example 1:​
Input: s = "aabbcc", k = 3, L = 3​
Output: "abcabc"​
Explanation:​
In "abcabc":

●​ Each identical character is at least 3 positions apart.​

●​ Every contiguous substring of length 3 (e.g., "abc", "bca", "cab") is not a palindrome.

Example 2:

Input: s = "aaabb", k = 2, L = 2

Output: "ababa"

Explanation:

In "ababa":

● Each 'a' is separated by at least 3 positions.

● Every substring of length 2 (e.g., "ab", "ba") is not a palindrome.

Constraints:

●​ 1 ≤ s.length ≤ 10⁴​

●​ 1 ≤ k ≤ s.length​

●​ 2 ≤ L ≤ s.length

Question 2: [40 Marks]

Once upon a time, in the mystical land of Gridora, a brave traveler found himself at the entrance
of an enchanted maze. This maze was no ordinary labyrinth—it was a vast N × M grid, where each
cell held a mysterious cost, representing the energy needed to step on it.
The traveler’s goal was clear: to journey from the top-left corner (0,0) to the bottom-right
corner (N-1, M-1), where the legendary treasure of Gridora awaited. However, there was a
catch—he could only move right or down at each step.

The maze was treacherous, and every step drained his energy. The traveler had to be wise and
choose a path that would minimize his total energy consumption to reach the treasure.

The Rules of the Journey:

1.​ The traveler starts at position (0,0) and must reach (N-1, M-1).​

2.​ Vjr e. D. FEach step costs energy, as defined by the number on the cell.​

3.​ He can only move right or down—never left or up.​

4.​ His challenge is to find the path that requires the least amount of energy to complete the
journey.

Example 1:

Input:

3 3

1 3 1

1 5 1

4 2 1

Output:

Explanation:​
The minimum-cost path is (0,0) → (0,1) → (0,2) → (1,2) → (2,2) with cost:​
1 + 3 + 1 + 1 + 1 = 7
Constraints:

●​ 1≤N,M≤1000
●​ 1≤grid[i][j]≤100

You might also like