2025 August 30 Problems

88 views
Skip to first unread message

daryl...@gmail.com

unread,
Aug 30, 2025, 12:53:56 PMAug 30
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.

35. Search Insert Position Easy 49.6%




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



Anuj Patnaik

unread,
Aug 30, 2025, 1:24:09 PMAug 30
to leetcode-meetup
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
left = 0
right = len(nums) - 1
while left <= right:
mid = left + (right - left)//2
if nums[mid] == target:
return mid
if nums[mid] < target:
left = mid + 1
if nums[mid] > target:
right = mid - 1
return left

Aleksandr Ershov

unread,
Aug 30, 2025, 1:27:52 PMAug 30
to leetcode-meetup
Java - Easy problem

On Saturday, August 30, 2025 at 9:53:56 AM UTC-7 daryl...@gmail.com wrote:
Screenshot 2025-08-30 at 10.27.16 AM.png
Message has been deleted
Message has been deleted
Message has been deleted

Anuj Patnaik

unread,
Aug 30, 2025, 2:17:09 PMAug 30
to leetcode-meetup
class Solution:
def preimageSizeFZF(self, k: int) -> int:
left = 0
right = 5 * (k + 1)
#Calculating the minimum n that satisfies f(n) = k
while left < right:
mid = left + (right - left)//2
if Solution.numtrailingzeroes(mid) < k:
left = mid + 1
else:
right = mid
#Calculating the minimum n that satisfies f(n) = k + 1.
# Let m be the minimum m that satisfies f(m) = k + 1
#Let n be the minimum n that satisfies f(n) = k
#Let max_n be the maximum n that satisfies f(n) = k
# m = max_n + 1
#The number of integers between n and max_n is max_n - n + 1
#Thus, m - n = max_n - n + 1
left1 = 0
right1 = 5*(k+2)
while left1 < right1:
mid1 = left1 + (right1 - left1)//2
if Solution.numtrailingzeroes(mid1) < k + 1:
left1 = mid1 + 1
else:
right1 = mid1
return left1 - left
def numtrailingzeroes(n):
ct = 0
while n > 0:
n //= 5
ct += n
return ct











Carrie Lastname

unread,
Aug 30, 2025, 2:17:15 PMAug 30
to leetcode-meetup
35. Search Insert Position Easy 49.6%

    def searchInsert(self, nums: List[int], target: int) -> int:
        return bisect_left(nums, target)


On Saturday, August 30, 2025 at 9:53:56 AM UTC-7 daryl...@gmail.com wrote:

Anuj Patnaik

unread,
Aug 30, 2025, 2:18:17 PMAug 30
to leetcode-meetup
class Solution:
def preimageSizeFZF(self, k: int) -> int:
left = 0
right = 5 * (k + 1)
while left < right:
mid = left + (right - left)//2
if Solution.numtrailingzeroes(mid) < k:
left = mid + 1
else:
right = mid
if Solution.numtrailingzeroes(left) == k and Solution.numtrailingzeroes(left + 4)== k:
return 5
else:
return 0

Carrie Lastname

unread,
Aug 30, 2025, 2:20:02 PMAug 30
to leetcode-meetup
    def numMatchingSubseq(self, s: str, words: List[str]) -> int:
        t = 0
        word_counts = Counter(words)
        words = list(word_counts.keys())
        ps = {}
        for i in range(len(words)):
            ps[i] = 0
        for c in s:
            delete = []
            for i, p in ps.items():
                curr = words[i]
                if curr[p] == c:
                    ps[i] += 1
                    if ps[i] == len(curr):
                        delete.append(i)
                        t += word_counts[curr]
            for num in delete:
                del ps[num]
        return t

On Saturday, August 30, 2025 at 9:53:56 AM UTC-7 daryl...@gmail.com wrote:

Anuj Patnaik

unread,
Aug 30, 2025, 2:21:14 PMAug 30
to leetcode-meetup

Akashleena Sarkar

unread,
Aug 30, 2025, 3:05:55 PMAug 30
to leetcode-meetup
35. Search Insert Position Easy 49.6%

class Solution {
public:
    int searchInsert(vector<int>& nums, int target) {
        int low = 0, high = nums.size()-1;
        int mid = low + (high - low)/2;
        cout<< low << mid << high;
        if (target<nums[low])
            return 0;
        while (low <= high){
        mid = low + (high - low)/2;
            if (nums[mid] == target){
                cout<<mid;
                 return mid;
            }
               
            else if (nums[mid]<target){
                low = mid + 1;
            }
            else {
                high = mid - 1;
            }

        }

        if (low<=high)
            return low + 1;
        else
            return high + 1;

    }
};

Reply all
Reply to author
Forward
0 new messages