class Solution { public int[] twoSum(int[] nums, int target) { //clone the array and sorted as new array arr int[] arr = nums.clone(); Arrays.sort(arr); //algorithm to find the values that can can produced target int j=nums.length-1; int i=0; while(i!=j){ if(arr[i]+arr[j]>target){ j--; } else if (arr[i]+arr[j]
First for loop last element ku varumbothu, second for loop la i+1th element access pannina,"Array index of range " error varum. Ex. Array size = 5 na nama index 4 varatha access panna mudiyum. i=4 ah irukkumbotha i+1 use panna mudiyathu. So Inga i+1= 5. Maximum index 4 than, 5 use panna mudiyathu
Use Hashmap:
Time complexity : o(n)
class Solution {
public int[] twoSum(int[] nums, int target) {
Map map = new HashMap();
for(int i=0;i
In the worst case scenario the time complexity of Hashmap.containskey() is O(n).then this code is also O(n^2).isn't it??????????
@@najeebhafeel5180 first learn hashmap😐
@@kirubakaran1547 I asked u as a question.could u please explain please??
@@kirubakaran1547 hello bro where are you from
@@kirubakaran1547 hiii
Anna please solve all the 160 problems and post it day by day don't postpone it. It is very useful for me and my friends to develop our coding skills
after a really long time bro...i thought i would never see u again..thanks a lot!
Nice explanation sir. Thanks and waiting for tomorrows question!!
Super bro. 😀...all problems um solve panunga free time...it's really useful for beginners...... except me also..
Anna please add more videos on DSA
U r explanation very clear❤
welcome back thala..😁
Sir, could you teach DBMS in detail?
Super bro , daily video podunga
Please solve in python
Idhu c++ ah solve pandriga?
Well explained
Ena language use panurika
yen bro ivolo naala video podala ? Unga video kaaga neriya naal wait pannen
Sir, below that class solution line vector.. Yedhuku sir..
In my code return{}; -- error sir 😔
Anna why are u traversing i th for loop upto nums.size() instead that traversing upto nums.size()-1 is enough right?
Yes, you are right. Traversing to size - 1 is enough but this makes the code much easier to read and understand. Either way answer will be the same
Please give the above code in java
Anna inda problems normal users access pannalama?, Ila premium podanuma🤔
You can acess this problem only 10% of problem is for premium
Bro google salary paththi sollunga
Waiting for next problem
Java la epudi 2 values return pannuradhu ?
create a int array and size as 2 because we return a two position so that after add to the array two position just return the array itself
return new int[ ]{i,j};
number of arithmetic triplers leetcode problem solution in tamil c++ video poduga bro
Ivlo naal yen bro video podala
Ungaala nambhi than irukkom
Anna inaikana problem vedio post panunga
Anna nums.size() la size() yethukkaga
Built-in Function To find length of nums array
@@sankarganeshmr9126 is both size() and length () are same?
@@lokeshp1929 size() is for vector, length () is for string
Bro inaiku video en varla?
class Solution {
public int[] twoSum(int[] nums, int target) {
//clone the array and sorted as new array arr
int[] arr = nums.clone();
Arrays.sort(arr);
//algorithm to find the values that can can produced target
int j=nums.length-1;
int i=0;
while(i!=j){
if(arr[i]+arr[j]>target){
j--;
}
else if (arr[i]+arr[j]
Pls share the hint or best solution
Anna neega Google la Work panrigala ?
Yes
@@cjtunes350 Spr Anna
Anna what Procedure to join 8n Google ?
Solve the problem in python also Sir....
Bro codechef hackerrank problems solve panni video poduga bro
Python la solve panunga bro🙂
bro neenga problem solving python LA start panringala
ithu enna language
Anna python programming language la explain pannunga anna 🥺
N² kela epudi Pannuradhu ?
try by hash map
@@prakashbtw678 how ?
please provide your contact, I will explain
Bro 2 problem solve panunga bro oru video la
Bro audio konjo sounda panunga bro, intha video okey, some other video are not
Maybe nums[I]+nums[I+1]??
First for loop last element ku varumbothu, second for loop la i+1th element access pannina,"Array index of range " error varum.
Ex.
Array size = 5 na nama index 4 varatha access panna mudiyum.
i=4 ah irukkumbotha i+1 use panna mudiyathu.
So Inga i+1= 5. Maximum index 4 than, 5 use panna mudiyathu
Hi akka
Flutter bro
Python code la solve pannugga bro