finally an easy problem to boost my self confidence T_T
@thespicycabbage Жыл бұрын
confidence is real low. Had to come back to see how this was done lol
@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
@ahmadmtera2 ай бұрын
@@软件实验室 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 Жыл бұрын
Return nums + nums Easy peasy But your solution works better if there is a 3rd argument Nice one 👍
@akash-kumar737 Жыл бұрын
Use return nums*2 Easy peasy plus expandable.
@TaoZeng-z2w4 ай бұрын
How are you able to return nums + nums in Java?
@ahmadmtera2 ай бұрын
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 Жыл бұрын
Simple Sol: def concatenation (nums,x): return x * nums;
@business_central Жыл бұрын
Please do "Last day where you can still cross" , even LC doesn't have an official solution yet on it
@candylover24566 ай бұрын
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 Жыл бұрын
return ( nums + nums ) is very pythonic. Instead we can directly use the formula given in the qn 😌
@doc94487 ай бұрын
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 Жыл бұрын
Greattttt to see some easy problems solved!!! 🍻🍻🍻🍻
@dumbfailurekms Жыл бұрын
ans[i] = nums[i % len(nums)] or ans.append and define the range of the for loop as 2 *len(nums)
@dusvn14844 ай бұрын
Mby extend with same nums works good ?
@qazyhn94 Жыл бұрын
is only append is O(1) but append in the middle of the begining in list will be O(n) operation?
@dankr Жыл бұрын
thanks
@vishalroy7932 Жыл бұрын
Why did you gave up some of us were watching your videos daily
@cyberrebel4623 Жыл бұрын
return nums*2
@suspatrol9550 Жыл бұрын
nums.extend(nums) return nums
@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 Жыл бұрын
basically just return nums + nums right?
@aaditya_87 Жыл бұрын
yeah no idea why he made a video for this
@gopro12378 Жыл бұрын
Just return the list multiplied by 2 that is return nums * 2
@home390Ай бұрын
Return nums * 2 😜
@novascotia2015 Жыл бұрын
dude i came from your tweet
@satwiktatikonda764 Жыл бұрын
whts it?
@pritishbhakat Жыл бұрын
2444. Count Subarrays With Fixed Bounds plz solve this problem, I am stuck in it.