Posts

Showing posts from November, 2023

Don't be ashamed of N^2 II

Image
Medium-level problem but given the small constraints it becomes actually easy with an N^2 approach (N=2000). Find all the substrings and in the process use a mapping to calculate the sum, then check the sum%length condition. Code is down below, cheers, ACC. Number of Divisible Substrings - LeetCode 2950. Number of Divisible Substrings Medium 1 0 Add to List Share Each character of the English alphabet has been mapped to a digit as shown below. A string is  divisible  if the sum of the mapped values of its characters is divisible by its length. Given a string  s , return  the number of  divisible substrings  of   s . A  substring  is a contiguous non-empty sequence of characters within a string.   Example 1: Substring Mapped Sum Length Divisible? a 1 1 1 Yes s 7 7 1 Yes d 2 2 1 Yes f 3 3 1 Yes as 1, 7 8 2 Yes sd 7, 2 9 2 No df 2, 3 5 2 No asd 1, 7, 2 10 3 No sdf 7, 2, 3 12 3 Yes asdf 1, 7, 2, 3 13 4 No Input: word = "asdf" Output: 6 Explanation: The table above contains the

Access Time: HashTables and SortedLists

Image
Not a complicated problem: parse the given list, create a hash table mapping each employee to a list of sorted times. Calculate the time in minutes. Be careful with the conflicts in the sorted list (keys need to be unique, use any approach to guarantee that, you can see here ). Then for each employee check if time[index+2] - time[index] satisfies the criteria. Code is down below, cheers, ACC. High-Access Employees - LeetCode You are given a 2D  0-indexed  array of strings,  access_times , with size  n . For each  i  where  0 <= i <= n - 1 ,  access_times[i][0]  represents the name of an employee, and  access_times[i][1]  represents the access time of that employee. All entries in  access_times  are within the same day. The access time is represented as  four digits  using a  24-hour  time format, for example,  "0800"  or  "2250" . An employee is said to be  high-access  if he has accessed the system  three or more  times within a  one-hour period . Times with