0% found this document useful (0 votes)
19 views7 pages

Coding Assessment Instructions and Problems

The document outlines a coding assessment with various programming tasks, including a banana transport puzzle, anagram grouping, Sudoku validation, palindrome generation, and minimum window substring search. Additionally, it requires designing a database schema for a student club management system and answering specific SQL queries. The assessment emphasizes code readability, clear handwriting, and making assumptions when necessary.
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)
19 views7 pages

Coding Assessment Instructions and Problems

The document outlines a coding assessment with various programming tasks, including a banana transport puzzle, anagram grouping, Sudoku validation, palindrome generation, and minimum window substring search. Additionally, it requires designing a database schema for a student club management system and answering specific SQL queries. The assessment emphasizes code readability, clear handwriting, and making assumptions when necessary.
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

Name

Date
Roll Number

Coding Instructions:

• Handwriting: Ensure your handwriting is clear and legible.


• Code Readability: Write your code in a way that is easy to read and understand.
• Duration: 120 minutes
• Attempt Maximum Questions: Strive to attempt as many questions as possible
within the given time.
• Assumptions: If necessary, make clear and concise assumptions to solve the
problems.

Note:

• Be attentive to code quality and readability.


• If any assumptions are made, clearly mention them in your solutions.

Best of luck with your coding assessment!


Banana Transport Puzzle

A camel is tasked with transporting 3,000 bananas to a


destination 1,000 kilometers away.

Constraints:

1. The camel can carry up to 1,000 bananas at a time.

2. The camel consumes one banana per kilometer travelled.

3. The camel can make multiple trips between any two points to transport bananas.

Question:

What is the maximum number of bananas that can be transported to the destination, 1000
kilometers away?

Provide your calculations and reasoning.


Problem:
You are given an array of strings. Your task is to group the strings that are anagrams of each
other into separate lists. Two strings are considered anagrams if they contain the same
characters in the same frequencies, regardless of their order.

Write an algorithm to group the strings into their respective anagram groups.

Input:
An array of strings, e.g., ["eat", "tea", "tan", "ate", "nat", "bat"].

Output:
A list of groups where each group contains strings that are anagrams of each other.
For example, Output: [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]].

Example:

Input: ["eat", "tea", "tan", "ate", "nat", "bat"]


Output: [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]
You are given a partially filled 9x9 Sudoku board. Your task is to determine if the board is valid.
A Sudoku board is valid if:

1. Each row contains the digits 1-9 without repetition.


2. Each column contains the digits 1-9 without repetition.
3. Each of the 9 subgrids (3x3) contains the digits 1-9 without repetition.

Only the filled cells (non-"." cells) need to be validated. Empty cells (".") can be ignored.

Input:
A 9x9 grid, where each cell contains:

• A digit from '1' to '9'


• A dot (".") representing an empty cell.

Output:

• Return true if the board is valid according to the rules.


• Return false if the board violates any of the rules.

Example:

Input:
board = [
["5", "3", ".", ".", "7", ".", ".", ".", "."],
["6", ".", ".", "1", "9", "5", ".", ".", "."],
[".", "9", "8", ".", ".", ".", ".", "6", "."],
["8", ".", ".", ".", "6", ".", ".", ".", "3"],
["4", ".", ".", "8", ".", "3", ".", ".", "1"],
["7", ".", ".", ".", "2", ".", ".", ".", "6"],
[".", "6", ".", ".", ".", ".", "2", "8", "."],
[".", ".", ".", "4", "1", "9", ".", ".", "5"],
[".", ".", ".", ".", "8", ".", ".", "7", "9"]
]
Output: true
Write a program to print all 6-digit palindromes. A palindrome is a number that
reads the same forward and backward.
Given two strings s and t, return the minimum window in s which contains all the
characters in t.

Input:

s = "ADOBECODEBANC",

t = "ABC"

Output: "BANC"
You are hired to design a database for a university's student club management system. The
university has multiple clubs, each with a unique club name and a president. Students can
join one or more clubs, and every student has a unique student ID, name, and enrollment
year. Each club organizes multiple events, with details such as the event name, event date,
and club hosting the event.

Your task is to:

1. Design the database schema by identifying necessary tables, their attributes, and
relationships (primary key and foreign keys)

2. Make sure that the schema is in the 3NF.

3. Answer the following SQL queries once the schema is created.

SQL Queries:

1. List all students along with the clubs they are a part of.

o If a student is not part of any club, still include their name in the output.

2. Find the name of the club president and the number of events organized by
their club in the year 2024.

3. Retrieve the details of all events (event name, date, and club name) along with
the names of students who participated in them.

o Include events that no student attended.

Common questions

Powered by AI

A valid Sudoku board must satisfy three conditions: 1) Each row must contain the digits 1-9 without repetition, 2) Each column must contain the digits 1-9 without repetition, 3) Each of the 9 subgrids (3x3 sections) must also contain the digits 1-9 without repetition. For non-empty (digit-filled) cells, check these conditions individually. Ensure the entire board upholds these constraints for a 'true' validation result, as exemplified in the described board from Source 1.

Applying 3NF to the student club database involves ensuring tables lack transitive dependencies. Decompose into: 1) 'Students' with unique identifiers (any attributes functionally determined by student_id stay here). 2) 'Clubs' separating intrinsic club info to minimize redundancy (remove any non-key dependency outside club attributes). 3) 'Events' ensuring event info relies on clear primary keys devoid of extraneous detail connections. 'Student_Clubs' assembles multi-club membership overlooked only with associative needing referenced foreign key usage keying student_id, club_name congruence free of indirect dependency or redundancy .

To print all 6-digit palindromes, iterate over the range 100,000 to 999,999. A 6-digit palindrome has the form ABCCBA. For each number, set the first three digits ABC, then construct the last three digits in reverse order CBA. The algorithm: 1) Loop through the hundreds (A), tens (B), and units (C) digits; 2) Compute the three reverse digits to form a palindrome; 3) Print the number. This directly constructs palindromes, optimizing over general checks significantly .

To group anagrams, use a hash table where the key is the sorted tuple of the string characters. The algorithm involves: 1) Traverse each string in the array, 2) Sort the string and convert it to a tuple which becomes the hash table key, 3) Append the original string to the list in the hash table for that key. This groups all anagrams under their respective character set. For example, with input ['eat', 'tea', 'tan', 'ate', 'nat', 'bat'], 'eat', 'tea', and 'ate' resolve to the same key ('a', 'e', 't') and thus are grouped together .

A 3NF schema for a student club database involves: 1) Table 'Students' with columns (student_id, name, enrollment_year), where student_id is the primary key. 2) Table 'Clubs' with columns (club_name, president_id) with club_name as the primary key and president_id as a foreign key referencing Students. 3) Table 'Events' with columns (event_id, event_name, event_date, club_name) where event_id is the primary key and club_name is a foreign key referencing Clubs. 4) An associative table 'Student_Clubs' with columns (student_id, club_name), both foreign keys referencing Students and Clubs respectively. Ensure no redundancy or partial dependencies for 3NF compliance .

Validating a Sudoku board involves checking each row, column, and 3x3 subgrid for duplicates among 1-9 digits in the filled cells. Initiate with constructing empty sets for each row, column, and grid to track seen numbers. Iterate over the board, adding numbers from these filled cells to their corresponding sets while checking for violations (duplicates). If any row, column, or subgrid contains a duplicate, return false, else return true if all checks are clear. Given example yields a valid result .

To find the minimum window substring in string s containing all characters of string t, use a sliding window approach: 1) Utilize two pointers to denote the window's boundaries in s. 2) Use a counter to track required characters and another to maintain current counts within the window. 3) Expand the window by moving the right pointer until all characters are within the window. 4) Once complete, attempt to contract by moving the left pointer to find the smallest window while maintaining character availability. Aim for optimal time complexity by tracking counts efficiently. For example, in s = 'ADOBECODEBANC' and t = 'ABC', the minimum window is 'BANC' .

The task involves multiple trips. Initially, the camel carries 1,000 bananas but consumes 1 banana per km. To optimize, divide the distance into segments: 1) The camel can carry and return several loads, reducing increment trips and calculating remaining potential with balance limits. After transporting smaller load changes incrementally at thresholds recalculated (shorter distances merging into consistent endpoint traversal at last stretch), approximately 833 bananas can successfully be retained at final destination, factoring consumption and need for iterative trip reductions. Logical tweaking along journey attempts maximizes output .

The SQL query to list all students and their clubs, including those not in any club, uses a LEFT JOIN: SELECT Students.name, Clubs.club_name FROM Students LEFT JOIN Student_Clubs ON Students.student_id = Student_Clubs.student_id LEFT JOIN Clubs ON Student_Clubs.club_name = Clubs.club_name; This ensures all students appear with NULL club names if they aren't part of any club .

The camel can carry 1,000 bananas at a time and consumes 1 banana per kilometer. To calculate the maximum number of bananas transported, consider the 3 segments of the trip: 1) From 3,000 bananas at the start, the camel needs to make 5 trips (each carrying and consuming 1,000 bananas) to cover 200 km (consuming 2,000 bananas), leaving 1,000 to continue. 2) With 1,000 bananas remaining, 3 more trips are needed to move 333.33 km (consuming 1,000 bananas). 3) For the final 466.67 km, the camel has 333 bananas, consuming only 333 in moving 333 km, allowing it to transport the remaining 333 bananas over the final 333.33 km. However, beyond a logistical threshold past 600 km, the increments fall under remaining banana capacity, necessitating crunch iterations to target maximizing endpoint. Hence, revised calculations pivot adjusting current with iterative directivity to 833 bananas effectively being potentially transported.

You might also like