2025 September 6 Problems

109 views
Skip to first unread message

daryl...@gmail.com

unread,
Sep 6, 2025, 12:43:01 PMSep 6
to leetcode-meetup
Feel free to work on any of the problems you want; we'll have people present their solutions at 11:30.

Please post your solutions to this thread so others can use this as a reference.



2906. Construct Product Matrix Medium 31.3%

Please download and import the following iCalendar (.ics) files to your calendar system.

FloM

unread,
Sep 6, 2025, 1:16:29 PMSep 6
to leetcode-meetup
Time: O(numOfCars), Mem: O(1)
class Solution {
public:
int numberOfPoints(vector<vector<int>>& nums) {
int curStart = -1;
int curEnd = -2;

int sum = 0;

sort(nums.begin(), nums.end(), [](const vector<int>& a, const vector<int>&b){return a[0] < b[0];});

for(int ii=0; ii<nums.size(); ++ii)
{
int numStart = nums[ii][0];
int numEnd = nums[ii][1];

if (numStart > curEnd)
{
sum +=(curEnd - curStart + 1);
curStart = numStart;
curEnd = numEnd;
}
else
{
if (curEnd < numEnd)
{
curEnd = numEnd;
}
}
}

sum +=(curEnd - curStart + 1);

return sum;
}
};

Kevin Burleigh

unread,
Sep 6, 2025, 1:22:22 PMSep 6
to leetcode-meetup
2906. Construct Product Matrix Medium 31.3%

## Time: O(N_rows*N_cols) = O(N_elems)
## Space: O(N_rows*N_cols) = O(N_elems)
class Solution:
def constructProductMatrix(self, grid: List[List[int]]) -> List[List[int]]:
N_rows, N_cols = len(grid), len(grid[0])
N_vals = N_rows*N_cols

## Convert grid to simple vector.
vals = [0]*N_vals
for r_idx in range(N_rows):
for c_idx in range(N_cols):
vals[r_idx*N_cols + c_idx] = grid[r_idx][c_idx]

##
## Compute left and right products
## (excluding current value)
##

left_prods = [0]*N_vals
right_prods = [0]*N_vals

prod = 1
for v_idx in range(N_vals):
left_prods[v_idx] = prod
prod *= vals[v_idx]
prod = prod % 12345

prod = 1
for v_idx in reversed(range(N_vals)):
right_prods[v_idx] = prod
prod *= vals[v_idx]
prod = prod % 12345

## Compute result from left- and right-products.
for v_idx in range(N_vals):
vals[v_idx] = (left_prods[v_idx] * right_prods[v_idx]) % 12345

## Put the values back into grid.
## (to give impressive memory usage;
## would not recommend in practice!)
for r_idx in range(N_rows):
for c_idx in range(N_cols):
grid[r_idx][c_idx] = vals[r_idx*N_cols + c_idx]

return grid

Anuj Patnaik

unread,
Sep 6, 2025, 1:22:30 PMSep 6
to leetcode-meetup
class Solution:
def numberOfPoints(self, nums: List[List[int]]) -> int:
set_nums = set()
for i in range(len(nums)):
for k in range(nums[i][0], nums[i][1] + 1):
set_nums.add(k)
return len(set_nums)

On Saturday, September 6, 2025 at 10:16:29 AM UTC-7 FloM wrote:

Carrie Lastname

unread,
Sep 6, 2025, 1:38:55 PMSep 6
to leetcode-meetup
2848. Points That Intersect With Cars Easy 73.0%


def numberOfPoints(self, nums: List[List[int]]) -> int:
    nums.sort()
    total = 0
    i = 0
    while i < len(nums):
        curr = nums[i]
        total += curr[1] - curr[0] + 1
        j = i+1
        while j < len(nums):
            other = nums[j]
            if other[0] <= curr[1]:
                if other[1] > curr[1]:
                    total += other[1] - curr[1]
                    curr = other
                j += 1
            else:
                break
        i = j
    return total


On Saturday, September 6, 2025 at 9:43:01 AM UTC-7 daryl...@gmail.com wrote:
Message has been deleted

Sourabh Majumdar

unread,
Sep 6, 2025, 2:32:45 PMSep 6
to leetcode-meetup
Time complexity: O(nlogn) Space: O(n) class Solution {
public:
struct CarInterval{
int start;
int end;
};

bool CanMerge(CarInterval& car_interval1, CarInterval& car_interval2) {
if (car_interval2.start <= car_interval1.end) {
return true;
}

return false;
}
int numberOfPoints(vector<vector<int>>& nums) {
auto car_interval_comparator = [](CarInterval& car_interval1, CarInterval& car_interval2) {
if (car_interval1.start == car_interval2.start) {
return car_interval1.end >= car_interval2.end;
}

return car_interval1.start > car_interval2.start;
};


std::priority_queue<CarInterval, std::vector<CarInterval>, decltype(car_interval_comparator)> car_intervals;

for(auto car : nums) {
car_intervals.push(
CarInterval{
.start = car[0],
.end = car[1]
}
);
}


// finally merge
std::vector<CarInterval> merged_cars;
while(car_intervals.size() > 1) {
CarInterval first_car = car_intervals.top();
car_intervals.pop();

CarInterval second_car = car_intervals.top();
car_intervals.pop();

if (CanMerge(first_car, second_car)) {
CarInterval merged_car = CarInterval{
.start = std::min(first_car.start, second_car.start),
.end = std::max(first_car.end, second_car.end)
};

car_intervals.push(
merged_car
);
continue;
}

// othewise collect the first car and then put back the second car
merged_cars.push_back(first_car);
car_intervals.push(second_car);
}

// finally collect the last remaining car
CarInterval final_car = car_intervals.top();
car_intervals.pop();

merged_cars.push_back(final_car);

int count_points = 0;
for(auto car_interval : merged_cars) {
count_points += (car_interval.end - car_interval.start + 1);
}


return count_points;

}
};

On Saturday, September 6, 2025 at 11:27:48 AM UTC-7 patnai...@gmail.com wrote:
class Solution:
def constructProductMatrix(self, grid: List[List[int]]) -> List[List[int]]:
one_d = []
p = [[0 for _ in range(len(grid[0]))] for _ in range(len(grid))]
for i in grid:
for j in i:
one_d.append(j)
one_d_prod = Solution.product_except_self(one_d)
r = 0
c = 0
for k in range(len(one_d_prod)):
p[r][c] = one_d_prod[k]
c += 1
if c == len(grid[0]):
c = 0
r += 1
return p
def product_except_self(nums):
prod = [1] * len(nums)
prefix = 1
for i in range(len(nums)):
prod[i] = prefix
prefix = (prefix * nums[i]) % 12345
suffix = 1
for i in reversed(range(len(nums))):
prod[i] = (prod[i] * suffix) % 12345
suffix = (suffix * nums[i]) %12345
return res






Anuj Patnaik

unread,
Sep 6, 2025, 2:58:43 PMSep 6
to leetcode-meetup
return prod






Kevin Burleigh

unread,
Sep 6, 2025, 10:55:29 PMSep 6
to leetcode-meetup
Per our lunch discussion today...

For anyone who's looking for additional instruction / practice, here are some additional groups that might be of interest:

Hacker Dojo DSA Study Group
This group meets in person  every other Thursday evening 6:30-8:00pm in Sunnyvale.  There are usually two tracks:
  • mock interviews, where you give and/or receive a question from a peer
  • self-study, where you (and potentially some peers) study a problem/topic of interest
This group is especially good for extra practice solving problems in front of other people at a whiteboard.

Group Coding Club
This group meets remotely every other Saturday from 1:00-4:00pm Pacific.  The virtual environment allows folks to split off into discussion subgroups covering topics of interest like DSAs, help with projects, etc.  Usually I end up leading a subgroup  about DSAs / Leetcode or a related topic.

This group is good for instruction on DSAs, problem-solving, getting a question answered, etc.


Friday Interview Prep/DSA/CS Discussion Group
This is my group and meets remotely every Friday from 1:00-5:00pm Pacific.  It focuses on interview prep, but we try to cover any additional skills/concepts that essential to survival at a developer job (version control, testing, basic databases/networking/security, core math, OS concepts, etc.).

This group is especially good for instruction, problem-solving, working out the kinks in how you explain your thought process at an interview.   We often joke that "It's Not A Class!", so come prepared to interact!


Reply all
Reply to author
Forward
0 new messages