Use Case 1: Removing Duplicates in User Inputs
π Problem: Youβre developing a survey application where users enter their favorite programming languages. You want to store only unique languages.
Use Case 2: Maintaining Recent Search History (Without Duplicates)
π Problem: Build a feature that stores the recent search terms a user enters, preserving the order they searched them, but preventing repeated terms.
Use Case 3: Display Sorted List of Student Names
π Problem: You want to display a sorted list of student names in alphabetical order automatically.
4. Task Scheduling System (Using Queue & Stack)
Use Case: Maintain order of tasks (Queue for FIFO), redo/undo (Stack for LIFO).
PROJECTS
1. Caching System β HashMap
Problem:
You are designing a search system. To reduce database calls, you need to implement a caching mechanism that stores search results based on keywords.
Question:
Implement a method
getSearchResult(String keyword)
that first checks the cache. If the result is not cached, simulate fetching from a DB and store it in the cache.β€ Enhance it to store a max of 5 items. When a new item is added beyond this limit, remove the oldest entry (Use
LinkedHashMap
if necessary).
2. Unique Visitor Tracker β TreeSet
Problem:
Your website records user names visiting a page. Visitors can come multiple times, but you only want to display unique and alphabetically sorted names.
Question:
Given an array of visitor names (including duplicates), store and display the unique visitors in ascending order.
β€ Modify it to ignore case sensitivity (e.g., "John" and "john" should be treated as the same).
3. Leaderboard System β TreeMap
Problem:
Create a leaderboard that maps scores to player names. If two players have the same score, store both.
Question:
Write a program that accepts player names and scores from the user. Display the leaderboard sorted in descending order of scores.
β€ Allow multiple players to have the same score (hint: use
TreeMap<Integer, List<String>>
).
4. Product Order Frequency β HashMap
Problem:
You're tracking the frequency of products ordered in an e-commerce store.
Question:
Given a list of products ordered, write a program to display how many times each product was ordered.
β€ Modify the solution to sort the products by frequency (hint: use a custom comparator with a list).
5. Undo/Redo System β Stack
Problem:
You're building a text editor with Undo and Redo functionality. Every text change should be recorded.
Question:
Implement two operations:
undo()
β removes the last action and stores it in a redo stack
redo()
β restores the last undone action
β€ Allow user input for actions and simulate a text editor with options like:
Type text
Undo
Redo
Show current text
No comments:
Post a Comment