Convert 1D Array Into 2D Array | 2 Approaches | Leetcode 2022 | codestorywithMIK

preview_player
Показать описание
This is the 53rd Video of our Playlist "Leetcode Easy : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve an easy problem : Convert 1D Array Into 2D Array | 2 Approaches | Leetcode 2022 | codestorywithMIK

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Convert 1D Array Into 2D Array | 2 Approaches | Leetcode 2022 | codestorywithMIK
Company Tags : will update soon

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Summary :
Both approaches convert a 1D array (original) into a 2D array (result) with m rows and n columns. However, they differ in how they populate the 2D array.

First Approach (Nested Loops):

This method uses two nested loops: the outer loop iterates over the rows, and the inner loop iterates over the columns.
It keeps track of an index (idx) that is used to access elements in the 1D array and place them in the 2D array sequentially.
Simple and intuitive, especially when thinking about 2D arrays as rows and columns.
Second Approach (Single Loop with Division/Modulus):

Instead of nested loops, this approach uses a single loop that iterates over the entire length of the original array.
It calculates the row index as i / n and the column index as i % n to directly place elements into the 2D array.
This approach is more compact, leveraging division and modulus operations to map 1D indices to 2D indices.
Both methods check if the total number of elements in the original array matches m * n before proceeding. If not, they return an empty 2D array.

✨ Timelines✨
00:00 - Introduction

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik
Рекомендации по теме
Комментарии
Автор

Yesterday i got an on-campus job offer.
Your videos helped me alot to clear my technical interview.
Thanks a lot ❤❤

vanshjain
Автор

Bhai mey to kar liya morning mey hi bas aapke video ka wait kar rha tha 😊 mey comment karta huaapna code dusre channel se 😊

learn_in_shorts
Автор

I was not aware of the concept which you used in 2nd Approach. thanks for that

EB-otuu
Автор

0:23 - Full Support hai sir aapko. You are already doing so much for us, this is the bare minimum that we can do for you. SUBSCRIBED

gui-codes
Автор

Please make a video on 3rd ques of today's LC contest.

AmdinCire-iqjq
Автор

Mik Bhai, we want a discussion forum.This explanation ❤

srinivasaraolakkoji
Автор

Maine approach - 1 se solve karliya. Watching 2nd approach
Thanks ❤

aws_handles
Автор

Did on my own by first one (thanks for second method tho)

whothefisyash
Автор

Bhaiya, Please Leetcode Weekly contest ke questions ke bhi detailed solution upload karo!!

bhanupratapsinghrathore
Автор

Hello mik bro. I have my rubrik interview by the end of this month. we're told that there will by leetcode hard & cf 2000 rating graph, dp problems. I have studied both these topics from your channel. Any specific resource of questions from where I should practise questions now?

JustThis-koqp
Автор

Contest ka 3rd and 4th question upload karo 🙏

malvado
Автор

Another approach just by little observation
class Solution {
public int[][] construct2DArray(int[] original, int m, int n) {
int[][] ans=new int[m][n];
int l=original.length;
if(m*n!=l) return new int[0][0];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
ans[i][j]=original[i*n+j];
}
}
return ans;
}
}

ranveerbarnwal
Автор

sir contest solutions bhi upload kiya kariye

harshitmnnit
Автор

Bhai aap aaj ke contest ka 3rd qn solve kr do pls
Apne Aisa past me kiya hai per ye thoda sa different hai approach nhi bn paa rha

baahubaliankit
Автор

sir, please upload solution of C and D problem of today's contest (contest 413)

MANENDRAADVANI
Автор

3276. Select Cells in Grid With Maximum Score also solved this from the last directly jumped to bitmask dp solution why bitmask why bruteforces will note work what is bruteforces code intuition please explain

ankitghosh
Автор

bhai please contest ke bhi sawal ka video banaya karo😥

HussainVlogs
Автор

Sir leetcode weekly contest 413 ka hard solution dijiye please..

debangshudey
Автор

Done with Approach-1 😊
Here to see 2nd approach

ugcwithaddi
Автор

i had done this

class Solution {
public int[][] construct2DArray(int[] original, int m, int n) {
int len = original.length;
if(len != (m*n)){
return new int[0][0];
}
int[][] ans = new int[m][n];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
int idx = i*n + j;
ans[i][j] = original[idx];
}
}
return ans;
}
}

aizadiqbal