Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String solution(String S, int K) {
- // Days of the week in order
- String[] days = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
- // Map days to their indices for quick lookup
- Map<String, Integer> dayIndex = new HashMap<>();
- for (int i = 0; i < days.length; i++) {
- dayIndex.put(days[i], i);
- }
- // Find the current day index
- int currentIndex = dayIndex.get(S);
- // Calculate the new index using modular arithmetic
- int newIndex = (currentIndex + K) % 7;
- // Return the corresponding day
- return days[newIndex];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement