LeetCode 2054 Two Best Non Overlapping Events | Binary Search | Greedy | Razorpay Interview Question

preview_player
Показать описание
LeetCode Problem 2054 Two Best Non Overlapping Events [ 8 Dec 2024 ]

🔗 Resources & Links:

📌 Video Overview:
Dive deep into the solution for the LeetCode challenge titled '2054 Two Best Non Overlapping Events'. Whether you're kickstarting your coding journey or aiming for roles at tech giants like Facebook, Amazon, Apple, Netflix, or Google, this tutorial is tailored for you. We'll break down the problem step-by-step, ensuring clarity and understanding.

🌟 Key Highlights:
A comprehensive walkthrough of the problem statement.
An intuitive explanation for both novice and intermediate coders.
Practical insights for acing interviews with top tech companies.
Code walkthrough to grasp the algorithmic approach.

📌 Chapters:
00:00 Understanding Problem Statement
04:45 Approach - Brute Force
06:37 Approach - Sorting + Greedy
16:05 Code

🔖 Relevant Tags & Keywords:
#dsa #codingtutorials #ProblemSolving #TechSkills #datastructures #algorithm #dsa #leetcode #leetcodesolution #googleinterview #google #amazon #adobe #developerjobs #codeharmonylab #codeharmony #intuitive #leetcodemedium #neetcode #java #simulation #string #scaler #array #search #leetcodedaily #matrix #microsoftinterviewquestion #googleinterviewquestion #adobeinterviewquestion #leetcodedpsolution
#amazoninterviewquestion #appleinterviewquestion #adobeinterviewquestion #Googleinterviewquestion #metainterviewquestion
#easy #leetcode2054 Two Best Non Overlapping Events
#razorpay #binarysearch #greedy #array #dp #binary

Join me on this coding adventure! Let's learn, grow, and conquer challenges together. 🔥
Рекомендации по теме
Комментарии
Автор

Excellent explanation. Can you please help me with this code? It runs well while memoization is not added and throws TLE, but after adding memoization, the code starts to throw an error. Thanks in advance.
public int solve(int[][] events, int index, int lastTime, int count, int[][] dp) {
if (index >= events.length || count <= 0) {
return 0;
}
if (dp[index][count - 1] != -1) {
return dp[index][count];
}

int include = 0;
if (lastTime < events[index][0]) {
include = events[index][2] +
solve(events, index + 1, events[index][1], count - 1, dp);
}
int notInclude = solve(events, index + 1, lastTime, count, dp);
return dp[index][count - 1] = Math.max(include, notInclude);

}

public int maxTwoEvents(int[][] events) {
Arrays.sort(events, Comparator.comparingInt(a -> a[0]));
int[][] dp = new int[events.length][2];
for (int[] temp : dp) {
Arrays.fill(temp, -1);
}
solve(events, 0, 0, 2, dp);
return Math.max(dp[0][0], dp[0][1]);
}

raviprakash