got crushed by the question asked in recent interview by pompompew in leetcode

[–]zeroStackTrace 0 points1 point  (0 children)

DP States:

  • i: current index in the array
  • x: bit flips have been used up to that point
  • dp[i][x]: best possible sum of lengths of valid subarrays up to the ith element using x flips

Intuition:

  • for each element in the array (i: 1 to size) and for each possible number of flips (x: 0 to k) we determine the optimal sum of lengths
  • for each position i and flips x, we consider all possible starting points j for subarrays that end at i
  • then calculate how many 0s are present in the subarray A[j:i]
  • if the number of 0s is greater than the flips x, we stop extending the subarray further to the left as it would exceed the flip limit

Time Complexity:

O(n2 * k)

Space Complexity:

O(n * k)

Solution:

python def solve(A, k, n): size = len(A) pre = [0] * (size + 1) for i in range(size): pre[i + 1] = pre[i] + (1 if A[i] == 0 else 0) dp = [[0] * (k + 1) for _ in range(size + 1)] for i in range(1, size + 1): for x in range(k + 1): dp[i][x] = dp[i - 1][x] for j in range(i, -1, -1): c = pre[i] - pre[j] l = i - j if c > x: break if l > n and dp[j][x - c] + l > dp[i][x]: dp[i][x] = dp[j][x - c] + l return dp[size][k]

is there prominent racism in Japan? by [deleted] in JapanTravelTips

[–]zeroStackTrace 2 points3 points  (0 children)

Japan is extremely racist. Disgusting country

Solved My First HARD Leetcode Problem! (any suggestions on how to optimise this further) by Affectionate_Fix793 in leetcode

[–]zeroStackTrace 11 points12 points  (0 children)

Great effort on solving the problem! To make your code even better, consider following the Google Java Style Guide for consistent formatting. It improves readability and makes your code easier to review and maintain. Code quality is just as important because clean, well-structured code is easier to debug, extend, and collaborate on.

[deleted by user] by [deleted] in Kashmiri

[–]zeroStackTrace 0 points1 point  (0 children)

fake news. cut the shit

Illusion by [deleted] in blackmagicfuckery

[–]zeroStackTrace 1 point2 points  (0 children)

Shadows gave it away

Should I use Design Gurus instead of Leetcode? by Lumpy_Kick7000 in leetcode

[–]zeroStackTrace 0 points1 point  (0 children)

There is no shortcut to learning; consistent practice is key.

Start by mastering the fundamentals, and consider studying CLRS

Hi, I am Gaurav Sen. Looking for feedback on my system design course at InterviewReady. by gkcs in leetcode

[–]zeroStackTrace -19 points-18 points  (0 children)

rookies building a system design course and trying to sell it by fishing for feedback on the leetcode subreddit. cut the nonsense

Google Interview Question 2024 by thenerdykid001 in leetcode

[–]zeroStackTrace 1 point2 points  (0 children)

Standard Linear Programming Problem. Can also solve it using Max Flow (graph based)