Channel Avatar

DeepCodes @UCvCZPc23yKBe_f6T58EXG0g@youtube.com

2.4K subscribers - no pronouns :c

LeetCode solutions with straightforward explanations and exa


Welcoem to posts!!

in the future - u will be able to do some more stuff here,,,!! like pat catgirl- i mean um yeah... for now u can only see others's posts :c

DeepCodes
Posted 1 year ago

Hi Everyone,
Recursive solution for today's Q
drive.google.com/file/d/1a28N-Krvj3PRYQZySwnJmICbj…

2 - 0

DeepCodes
Posted 1 year ago

Follow on LinkedIn: www.linkedin.com/in/deep23/

10 - 0

DeepCodes
Posted 1 year ago

Hi all, Happy Weekend!
Today's Leetcode daily challenge video can be found here: https://youtu.be/_Fsz8MjKO4s

1 - 0

DeepCodes
Posted 1 year ago

Hello all Good Morning , I might upload a video later today, didn't get enough time in the morning.
You can go through the notes: drive.google.com/file/d/1jWl3lmj6x3yIFJrtVRw9HoZUw…
Thanks!

8 - 1

DeepCodes
Posted 1 year ago

In what area you guys need support/guidance

4 - 3

DeepCodes
Posted 1 year ago

Youtube still processing today's video!

4 - 4

DeepCodes
Posted 1 year ago

Intuition for 54. Spiral Matrix

To print the given matrix in a spiral way, we need to keep track of the current row and current column. Further, track all the boundaries because we traverse only the boundaries and that keeps changing. Therefore track:
int it: ith row from top
int ib: ith row from bottom
int jl: jth col from left
int jr: jth col from right

These boundaries shrink, and we just need to maintain these variables.

class Solution {
public:
vector<int> spiralOrder(vector<vector<int>>& matrix) {
int r = matrix.size(), c = matrix[0].size(), it = 0, jl = 0, ib = r-1, jr = c-1;
vector<int>ans;
while (it <= ib && jl <= jr) {

//traverse top most available row from left to right boundary
for (int k = jl; k <= jr; k++) {
ans.push_back(matrix[it][k]);
}
it++; //shrink top boundary

//traverse right most available col from top to bottom boundary
for (int k = it; k <= ib; k++) {
ans.push_back(matrix[k][jr]);
}
jr--; //shrink right boundary

//matrix can be completed in mid-way too
if (it > ib || jl > jr) {
return ans;
}

//traverse bottom most available row in reverse from right to left boundary
for (int k = jr; k >= jl; k--) {
ans.push_back(matrix[ib][k]);
}
ib--; //shrink bottom boundary

//traverse left most available col in reverse from bottom to top boundary
for (int k = ib; k >= it; k--) {
ans.push_back(matrix[k][jl]);
}
jl++; //shrink left boundary
}
return ans;
}
};

5 - 1

DeepCodes
Posted 1 year ago

Which MNCs OA/Coding Qs do you want to learn next?

2 - 0

DeepCodes
Posted 1 year ago

Today's Daily Challenge Thought Process and Discussion
Q: 1046. Last Stone Weight

Question Understanding
Perform steps 1 and 2 until the last stone remaining
1. Choose two heaviest stones each time, let's say st1 and st2

2. If st1 == st2 then both are destroyed, else if st1 > st2 then st2 id destroyed and st1 will change to st1-st2, else st2 > st1 then st1 is destroyed and st2 = st2-st1

3. Return the weight of the last remaining stone

Intuition
Focus on line: choose two heaviest stones to perform the operations
Note: Step 2 will change the weight of the stone each time
Approach 1: Sort the stones array each time before choosing two stones
Approach 2: Use max heap that returns the max-weight stone

Approach
1. A priority queue is created by making the values of the stones negative.

2. The loop continues until there is only one stone remaining in the heap. In the loop, the two heaviest stones are removed from the queue, and it is checked if they are equal.

3. If the two stones are not equal, their difference weight is calculated, and the resulting stone is pushed back onto the queue.

4. At the end, the weight of the last remaining stone is returned, or 0 if there are no stones left.

LIKE 👍

13 - 0

DeepCodes
Posted 1 year ago

Hello all,
Unlock your full potential with daily doses of Data Structures and Algorithms on our LinkedIn page. Follow us now and embark on a journey of constant learning and growth!
www.linkedin.com/company/deepcodes

8 - 0