Design a Todo List Where users can add tasks, mark them as complete, or get a list of pending tasks. Users can also add tags to tasks and can filter the tasks by certain tags.
Implement the
TodoListclass:
TodoList()Initializes the object.int addTask(int userId, String taskDescription, int dueDate, List<String> tags)Adds a task for the user with the IDuserIdwith a due date equal todueDateand a list of tags attached to the task. The return value is the ID of the task. This ID starts at1and is sequentially increasing. That is, the first task’s id should be1, the second task’s id should be2, and so on.List<String> getAllTasks(int userId)Returns a list of all the tasks not marked as complete for the user with IDuserId, ordered by the due date. You should return an empty list if the user has no uncompleted tasks.List<String> getTasksForTag(int userId, String tag)Returns a list of all the tasks that are not marked as complete for the user with the IDuserIdand havetagas one of their tags, ordered by their due date. Return an empty list if no such task exists.void completeTask(int userId, int taskId)Marks the task with the IDtaskIdas completed only if the task exists and the user with the IDuserIdhas this task, and it is uncompleted.
2599. Make the Prefix Sum Non-negative
You are given a 0-indexed integer array
nums. You can apply the following operation any number of times:
- Pick any element from
numsand put it at the end ofnums.The prefix sum array of
numsis an arrayprefixof the same length asnumssuch thatprefix[i]is the sum of all the integersnums[j]wherejis in the inclusive range[0, i].Return the minimum number of operations such that the prefix sum array does not contain negative integers. The test cases are generated such that it is always possible to make the prefix sum array non-negative.
2604. Minimum Time to Eat All Grains
There are
nhens andmgrains on a line. You are given the initial positions of the hens and the grains in two integer arrayshensandgrainsof sizenandmrespectively.Any hen can eat a grain if they are on the same position. The time taken for this is negligible. One hen can also eat multiple grains.
In
1second, a hen can move right or left by1unit. The hens can move simultaneously and independently of each other.Return the minimum time to eat all grains if the hens act optimally.
You are given two 0-indexed integer arrays
nums1andnums2of the same length. A pair of indices(i,j)is called beautiful if|nums1[i] - nums1[j]| + |nums2[i] - nums2[j]|is the smallest amongst all possible indices pairs wherei < j.Return the beautiful pair. In the case that there are multiple beautiful pairs, return the lexicographically smallest pair.
Note that
|x|denotes the absolute value ofx.- A pair of indices
(i1, j1)is lexicographically smaller than(i2, j2)ifi1 < i2ori1 == i2andj1 < j2.