Untitled
unknown
plain_text
2 months ago
743 B
4
Indexable
// T.C: O(n) // S.C: O(24) = O(1), since the remainders range from 0 to 23 class Solution { public int countCompleteDays(int[] hours) { int result = 0; int[] remainderCount = new int[24]; // Array to count frequencies of remainders for (int hour : hours) { int remainder = hour % 24; // Current remainder int complement = (24 - remainder) % 24; // Complement remainder // Add the frequency of the complement remainder result += remainderCount[complement]; // Increment the frequency of the current remainder remainderCount[remainder]++; } return result; } }
Editor is loading...
Leave a Comment