Concatenation of Array - Leetcode 1929 - Python

  Рет қаралды 38,448

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 32
@thespicycabbage
@thespicycabbage Жыл бұрын
finally an easy problem to boost my self confidence T_T
@thespicycabbage
@thespicycabbage Жыл бұрын
confidence is real low. Had to come back to see how this was done lol
@the8426
@the8426 Жыл бұрын
Another way is to create ans 2x len of nums with 0 as placeholder. Loop through nums and add the current value of nums to the corresponding index of ans and corresponding index ans + len of nums. So in the first iteration, we add the value at nums[0] to ans[0] and ans[0+len(nums)] which is ans[3] and so on. The time complexity improves to O(n) instead of O(n+n) lil difference.
@软件实验室
@软件实验室 6 ай бұрын
but the creation of the array ans with placeholders takes O(2n) time
@ahmadmtera
@ahmadmtera 2 ай бұрын
@@软件实验室 who cares... At the end we need to return an array of length 2n. Working with arrays is better and cheaper in terms of processing power compared to using an object like List. Storage is also cheap and nums is eventually discarded so in both cases we're left with a Space Complexity of O(2n) as requested.
@piyusharyaprakash4365
@piyusharyaprakash4365 Жыл бұрын
Return nums + nums Easy peasy But your solution works better if there is a 3rd argument Nice one 👍
@akash-kumar737
@akash-kumar737 Жыл бұрын
Use return nums*2 Easy peasy plus expandable.
@TaoZeng-z2w
@TaoZeng-z2w 4 ай бұрын
How are you able to return nums + nums in Java?
@ahmadmtera
@ahmadmtera 2 ай бұрын
Python will screw you over the minute you step into any language that doesn't support such high level features. In problem solving, one should learn how to solve problems by learning how to type out the relatively low level instructions that deal with basic building blocks like arrays, and not by using a language specific feature that does that for them.
@yfjsdgzjdnfn
@yfjsdgzjdnfn Жыл бұрын
Simple Sol: def concatenation (nums,x): return x * nums;
@business_central
@business_central Жыл бұрын
Please do "Last day where you can still cross" , even LC doesn't have an official solution yet on it
@candylover2456
@candylover2456 6 ай бұрын
since its a nested loop though, wouldn't this be O(n^2)? Confused here, can anyone please help?
@软件实验室
@软件实验室 6 ай бұрын
n is the input size, but the outer loop's iteration is independent with the inner loop, which in this case is still O(n)
@lavanya_m01
@lavanya_m01 Жыл бұрын
return ( nums + nums ) is very pythonic. Instead we can directly use the formula given in the qn 😌
@doc9448
@doc9448 7 ай бұрын
I submitted 3 times: nested for loops, a while loop (with the same for loop inside), and then simply "return nums + nums". The return was the most efficient according to python. A true easy this was.
@ingluissantana
@ingluissantana Жыл бұрын
Greattttt to see some easy problems solved!!! 🍻🍻🍻🍻
@dumbfailurekms
@dumbfailurekms Жыл бұрын
ans[i] = nums[i % len(nums)] or ans.append and define the range of the for loop as 2 *len(nums)
@dusvn1484
@dusvn1484 4 ай бұрын
Mby extend with same nums works good ?
@qazyhn94
@qazyhn94 Жыл бұрын
is only append is O(1) but append in the middle of the begining in list will be O(n) operation?
@dankr
@dankr Жыл бұрын
thanks
@vishalroy7932
@vishalroy7932 Жыл бұрын
Why did you gave up some of us were watching your videos daily
@cyberrebel4623
@cyberrebel4623 Жыл бұрын
return nums*2
@suspatrol9550
@suspatrol9550 Жыл бұрын
nums.extend(nums) return nums
@BennduR
@BennduR Ай бұрын
var getConcatenation = function(nums) { let ans = []; for(i = 0; i < nums.length; i++){ ans[i] = nums[i]; ans[i+nums.length] = nums[i]; } return ans; } 1ms runtime is this good or bad and why? Thx
@turtlenekk4354
@turtlenekk4354 Жыл бұрын
basically just return nums + nums right?
@aaditya_87
@aaditya_87 Жыл бұрын
yeah no idea why he made a video for this
@gopro12378
@gopro12378 Жыл бұрын
Just return the list multiplied by 2 that is return nums * 2
@home390
@home390 Ай бұрын
Return nums * 2 😜
@novascotia2015
@novascotia2015 Жыл бұрын
dude i came from your tweet
@satwiktatikonda764
@satwiktatikonda764 Жыл бұрын
whts it?
@pritishbhakat
@pritishbhakat Жыл бұрын
2444. Count Subarrays With Fixed Bounds plz solve this problem, I am stuck in it.
Symmetric Tree - Leetcode 101 - Python
6:40
NeetCodeIO
Рет қаралды 39 М.
Rotating the Box - Leetcode 1861 - Python
15:14
NeetCodeIO
Рет қаралды 5 М.
ВЛОГ ДИАНА В ТУРЦИИ
1:31:22
Lady Diana VLOG
Рет қаралды 1,2 МЛН
"Идеальное" преступление
0:39
Кик Брейнс
Рет қаралды 1,4 МЛН
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН
10 Crazy Python Operators That I Rarely Use
11:37
Indently
Рет қаралды 43 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 576 М.
Coding Unbreakable Encryption in C | One-Time Pad
17:42
HirschDaniel
Рет қаралды 3,5 М.
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 735 М.
Why is everyone LYING?
7:56
NeetCodeIO
Рет қаралды 348 М.
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 93 М.
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 245 М.
Learn Python OOP in under 20 Minutes
18:32
Indently
Рет қаралды 107 М.
ВЛОГ ДИАНА В ТУРЦИИ
1:31:22
Lady Diana VLOG
Рет қаралды 1,2 МЛН