Day of the Year
Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.
1 | class Solution { |
Number of Dice Rolls With Target Sum
You have d dice, and each die has f faces numbered 1, 2, …, f.
Return the number of possible ways (out of fd total ways) modulo 10^9 + 7 to roll the dice so the sum of the face up numbers equals target.
1 | class Solution { |
Swap For Longest Repeated Character Substring
Given a string text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters.
1 | class Solution { |
Online Majority Element In Subarray
Implementing the class MajorityChecker, which has the following API:
- MajorityChecker(int[] arr) constructs an instance of MajorityChecker with the given array arr;
- int query(int left, int right, int threshold) has arguments such that:
- 0 <= left <= right < arr.length representing a subarray of arr;
- 2 * threshold > right - left + 1, ie. the threshold is always a strict majority of the length of the subarray
Each query(…) returns the element in arr[left], arr[left+1], …, arr[right] that occurs at least threshold times, or -1 if no such element exists.
1 | MajorityChecker majorityChecker = new MajorityChecker([1,1,2,2,1,1]); |
1 | class MajorityChecker { |