Cognizant Java Coding Interview | Nothing is impossible if you solve code like this

  Рет қаралды 177,473

CloudTech

CloudTech

Жыл бұрын

In this video, we covered Cognizant Java Coding Interview Questions. The candidate got selected in the company with the offer of 9 LPA.
We solved below problem
1.) Place all the occurrence of even number in the array before odd numbers using Java
(paid link)
Recommended Books:
=====================================
-Programming with Java - amzn.to/3CqBLEw
-Clean Code - amzn.to/3SQHtoy
(paid link)
Computer & Monitor
=====================================
-Dell Laptop - amzn.to/3e0BNK6
-Samsung Monitor - amzn.to/3Cq3LrP

Пікірлер: 151
@atulyt2129
@atulyt2129 Жыл бұрын
Really helpful as a fresher, thank you, subbed ✌️ Please keep posting such videos
@k283535
@k283535 Жыл бұрын
You guys are helping many needy people
@DriveandThrive
@DriveandThrive Жыл бұрын
I liked his approach of course pointers is better but this is a simpler method for a junior developer position. Also, as far as 0(n) you might as well make this even simpler imo. Like: public static ArrayList evenThenOdd(int[] array){ ArrayList even = new ArrayList(); ArrayList odd = new ArrayList(); for(int i = 0; i < array.length; i++) { if(array[i] % 2 == 0) { even.add(array[i] ); } else { odd.add(array[i]); } } even.addAll(odd); System.out.println(even); return even; } If you are going the simple route just go really easy. If you want to do 0(1) ok even better but no need to over complicate things.
@reeeeel2858
@reeeeel2858 Жыл бұрын
We can use a queue to store odd elements,nd later copy them in to array without having to run the whole loop once again for odd numbers , nd hence loop runs only for the count of odd numbers . If order should be maintained,else we can use 2 pointer.
@akashm9974
@akashm9974 Жыл бұрын
We can do it in a single pass (iterating all the element only once) & in-place (not creating an extra array, using the input array) by 2-pointers approach. public static void main(String[] args) { int[] arr = {1,2,5,4,7,8,11,20}; int i = 0; for(int j = 0; j < arr.length; j++){ if(arr[j]%2 == 0){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; } } System.out.println(Arrays.toString(arr)); } !! order will change for odd number !! Hope this is helpful :)
@vamsisai8924
@vamsisai8924 Жыл бұрын
Noice
@sourabhbidikar4143
@sourabhbidikar4143 5 ай бұрын
As per my understanding if we take auxiliary space it's okay but you should never ever manipulate input data until and unless asked explicitly
@ravishukla7493
@ravishukla7493 Жыл бұрын
Solved this question using a single loop, although my first approach was also similar to the solution provided in the video.
@adityau5823
@adityau5823 Жыл бұрын
Please make more videos for java developer great going 💯💯💯🙌🙌🙌🙌🙌🙌🙌. Pls bring someone 1 year experience people also pure devlopment based like only spring one .
@Thinkdifferentsagnic
@Thinkdifferentsagnic Жыл бұрын
Here is another solution which might be useful for some- We declare another array having double the length of the intial array and then start putting the odd elements on the new array starting from 0th index till initial array's length also simultaenously, we put the even elements in the new array starting from the index , equal to the length of the inital array till needed. Finally we put a condition which checks till when was odd elements and even elements were pushed into the new array and display till those counter values. Code (Hope it's Helpful)- class oddeven { public static void main(String[] args) { int count=0; int[] arr1={1,2,5,4,7,8,11,20}; int [] b=new int[(arr1.length)*2]; int evcount=arr1.length; for(int i=0;i
@redstarentertainment2621
@redstarentertainment2621 Жыл бұрын
You made it more complex... I have posted a solution using PHP. See if you can find the comment.
@vaibhavraj8126
@vaibhavraj8126 Жыл бұрын
Nice work brother keep it up
@AnuragTripathy93
@AnuragTripathy93 Жыл бұрын
There's a company that still asks such easy questions and allows extra space. Good to know!!!
@kapilrana4043
@kapilrana4043 Жыл бұрын
great bro they are asking very easy problem infosys level problem is much tougher thant this for 9.5lpa role
@shamgavhane6219
@shamgavhane6219 Жыл бұрын
Very helpful sir 👍
@anandkumar-ir8zj
@anandkumar-ir8zj Жыл бұрын
You provided real scenario . Some youtubers are faking interview questions to get views , by putting much difficult questions
@venkatbhaskar3027
@venkatbhaskar3027 Жыл бұрын
ha ha this is a biggest fake show, stupid
@ankitbudhewad1964
@ankitbudhewad1964 Жыл бұрын
Nice, Please create one video on Design pattern And java 8 features Explain therotical part and program please.
@falaksajjad4910
@falaksajjad4910 Жыл бұрын
It is also constructed using for loop in a single method .
@Laughing_india_
@Laughing_india_ Жыл бұрын
this is too easy i think nowadays they don't ask that kind of questions they must be ask about dynamic programming
@onepercentbetter3313
@onepercentbetter3313 Жыл бұрын
Haha
@souravkumar-hl2ot
@souravkumar-hl2ot Жыл бұрын
Haha
@digvijayyamagekar7139
@digvijayyamagekar7139 Жыл бұрын
This is too easy because this is not real interview 😂😂
@amoghyelasangikar5836
@amoghyelasangikar5836 Жыл бұрын
It depends on company
@mahidharreddy1213
@mahidharreddy1213 Жыл бұрын
Yes it’s true
@Shorts_n_Laughs
@Shorts_n_Laughs Жыл бұрын
Wow man you are lucky... They ask very easy question for 9LPA
@ScientificMyths2706
@ScientificMyths2706 Жыл бұрын
Using Stream().filter() we can process the array twice one for even no and other for odd!! Then using string builder concat both the arrays!!
@musicmasti1938
@musicmasti1938 Жыл бұрын
Thank you sir
@monikadesai8251
@monikadesai8251 Жыл бұрын
Superb 👏👏
@TiwariAman2912
@TiwariAman2912 Жыл бұрын
During Gen C(4 LPA),They asked me to reverse an array through swaping, Transpose a Matrix,Basic linear search and Reverse a string.
@cloudtech5260
@cloudtech5260 Жыл бұрын
Will try to solve these problems 👍
@moyeensyed6637
@moyeensyed6637 Жыл бұрын
Thank you
@stayvloging
@stayvloging Жыл бұрын
i have done this question in 3 minute similarly like this without watching your video
@cnshobbs6748
@cnshobbs6748 Жыл бұрын
Fresher be like - Wts going on here🙄😑
@tejasnagapure6734
@tejasnagapure6734 Жыл бұрын
Bro but fresher's always try to find out the easy solution as compare to experienced
@riturajghosh937
@riturajghosh937 Жыл бұрын
If the order can be compromised then two pointer approach can be used for better space complexity. And that will be optimal solution for this problem.
@sanazbegum1844
@sanazbegum1844 Жыл бұрын
In java pointer is not used
@yashpawar7881
@yashpawar7881 Жыл бұрын
@@sanazbegum1844 lol he didn't mean that pointer, two pointer approach is a method where we use two variables to solve problem
@sanazbegum1844
@sanazbegum1844 Жыл бұрын
@@yashpawar7881 ok bro I am not aware of that and i am a 2 nd year cse student
@greyhat6599
@greyhat6599 Жыл бұрын
We can also use two pointer method . Take Start and end variables . Run a loop which will iterate over array . Swap both the nos . if start is odd and end is even. That's it ! ( Disadvantage, here is , the order of elements get disturbed )
@cloudtech5260
@cloudtech5260 Жыл бұрын
GreyHat, You are absolutely right with this approach 👍
@sanyamkothari4469
@sanyamkothari4469 Жыл бұрын
order will be the same bro!
@sahil5694
@sahil5694 Жыл бұрын
@@sanyamkothari4469 nope dude, order will change for odd numbers as it will be added from the end of the array... so the first occurence odd number will reach at the end the array.
@sanyamkothari4469
@sanyamkothari4469 Жыл бұрын
@@sahil5694 ok , so he's talking about his approach . I thought it is about the approach in the vedio😅😅.
@priya_world
@priya_world Жыл бұрын
GreyHat can you please tell me how you build a logic
@reeeeel2858
@reeeeel2858 Жыл бұрын
I got this question in an exam of wipro for 3.5 or 3.6 package, I guess.
@DriveandThrive
@DriveandThrive Жыл бұрын
another approach could be: public static void evenThenOdd(int[] arr) { int i = 0; int j = arr.length - 1; while (i < j) { if (arr[i] % 2 == 0) { i++; } else if (arr[j] % 2 != 0) { j--; } else { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } for (int k = 0; k < arr.length; k++) { System.out.println(arr[k]); }
@josephpraveen6341
@josephpraveen6341 Жыл бұрын
Ur doing O(n square) .. but it is possible to do with O(n) using pointers
@lonestoryteller5430
@lonestoryteller5430 Жыл бұрын
It was easy. I was hoping for a solution without using extra space. I think that is possible.
@ranuchakravarti3277
@ranuchakravarti3277 Жыл бұрын
This is fresher's interview and mentioned 2yrs exp. ,and i was waiting for catch 😂😂
@akashtawade9264
@akashtawade9264 Жыл бұрын
Even and Odd program interviewer ask when you are fresher candidate and by the way it's very very very easy problem. Interviewer should ask dynamic programming instead of this.
@cloudtech5260
@cloudtech5260 Жыл бұрын
Hi Akash, Thanks for the feedback. We will try to cover dynamic programming in upcoming videos. 👍
@RohanKumar-yj7sz
@RohanKumar-yj7sz Жыл бұрын
My Solution: List al = new ArrayList(); int e = 0; for (int i : arr) { al.add(i % 2 == 0 ? e++ : al.size(), i); } return al.stream().mapToInt(k -> k).toArray();
@girirajsinghrathore1749
@girirajsinghrathore1749 Жыл бұрын
This should have been solved with space complexity o(1)
@rahul_singh_rajput3292
@rahul_singh_rajput3292 Жыл бұрын
if order doesn't matter then we can do this Q in O(N) and O(1) space using Two pointer ... otherwise we can do this Q in O(N) space and time if only order is matter not the element should be in sorted order .. if it's matter then we need to sort the arday first.. then the TC will be n*log(n) for sorting
@predatorgaming895
@predatorgaming895 Жыл бұрын
Freshers can do this with even more optimization
@Gametime00789
@Gametime00789 Жыл бұрын
Are these the questions they ask for coding round???...such simple ones??
@Timeless_Trader
@Timeless_Trader Жыл бұрын
Hi, I think of similar logic just that instead is creating new array, can't we use same array. Logic is like this. (I don't know how to code this). Start from left --> if number is odd > put it at n-1 place: Else if even don't change it's place. Count number of even or odd while traversing. If anybody can help me out on this, it would be much appreaciated.
@TheReddKite
@TheReddKite Жыл бұрын
This is so easy question,I don't think this is an actual interview fake
@vedantkulkarni5437
@vedantkulkarni5437 Жыл бұрын
This kind of questions i used to do in first year 🙆🏻‍♂️😂
@MG-Anandhu
@MG-Anandhu Жыл бұрын
Can i just print the elements instead of storing it in another array .
@vineethyadav4221
@vineethyadav4221 Жыл бұрын
For freshers what is the package for springboot if we are good at spring boot? and if we done a project on springboot is it a plus point ?
@cloudtech5260
@cloudtech5260 Жыл бұрын
Yes, having springboot in your tech stack id plus point, you may get better package.
@iiTzAkash
@iiTzAkash Жыл бұрын
optimization itna easy interview
@rahulg415
@rahulg415 Жыл бұрын
Can't we give odd number condition in else block instead of another for loop ?
@cloudtech5260
@cloudtech5260 Жыл бұрын
Hi Rahul, No. As we don't know the number of even number. If you add else then it will be even odd combination in between.
@rahulg415
@rahulg415 Жыл бұрын
@@cloudtech5260 Thanks for the response!
@AkashGupta-yo1wl
@AkashGupta-yo1wl Жыл бұрын
impressive how he build a logic ...i wonder how much it will take me to build logic like that.
@cyber_dbs
@cyber_dbs Жыл бұрын
what!
@AkashGupta-yo1wl
@AkashGupta-yo1wl Жыл бұрын
@@cyber_dbs the way that guy is coding in video.
@cyber_dbs
@cyber_dbs Жыл бұрын
don't mind me, but I was just surprised to see someone getting impressed by watching how to solve one of the easiest coding problem to solve.
@AkashGupta-yo1wl
@AkashGupta-yo1wl Жыл бұрын
@@cyber_dbs well i am just began my coding journey and for me it is really something ahead from what i am doing right now...
@chandanpatra3850
@chandanpatra3850 Жыл бұрын
2 pointer approch you can easily solved this question. Because this unsorted array
@pranoydas9654
@pranoydas9654 11 ай бұрын
Three for loop. What will be the complexity?
@sumanmodak1846
@sumanmodak1846 Жыл бұрын
This is very easy level question and I can't believe it that it is for 9Lpa.. I can do hard level questions and have buit full stack projects in Mern stack and in php frameworks also. But still unemployed. Sach me yaar..naseeb apna apna
@cloudtech5260
@cloudtech5260 Жыл бұрын
Hi Suman, Keep trying, you will soon get the job. Best of luck 👍
@sourabhprajapat6637
@sourabhprajapat6637 Жыл бұрын
can we connect suman
@GowthamiKaranam
@GowthamiKaranam Жыл бұрын
How to prepare for logical code??
@Shorts_n_Laughs
@Shorts_n_Laughs Жыл бұрын
Are they still recruiting for the same post?
@xolo2617
@xolo2617 Жыл бұрын
Very easy problem ***
@ashaymishra7082
@ashaymishra7082 Жыл бұрын
Too easy🙂
@prashanthreddy-sd9ju
@prashanthreddy-sd9ju Жыл бұрын
Miku 6 to 7 years experience unna kuda firstly they will ask core Java question only its true
@raviravi-gg5ck
@raviravi-gg5ck 6 ай бұрын
Alternative approach List list1 = Stream.array(arr1).filter(e -> e%2==0).collect(Collectors.toList); List list2= Stream.array(arr1).filter(e -> e%2 !=0).collect(Collectors.toCollection(()->(list1)); System.out.println(list2);
@sudarshanpatil2227
@sudarshanpatil2227 Жыл бұрын
hey, can you solve this without using extra array?
@amitmahato6404
@amitmahato6404 Жыл бұрын
Two pointers. First iterate over the array and count even numbers. Take two pointers l=0, r=count+1, as odd numbers will be placed after even numbers. Then again iterate over the array and check if it's even make a[l]=a[i], then l++. Vice versa for odd numbers
@zehansayed3631
@zehansayed3631 Жыл бұрын
9 lpa is very less 20 lpa is good
@themoonlight1922
@themoonlight1922 Жыл бұрын
Try to do it in place
@saurabhgupta6681
@saurabhgupta6681 Жыл бұрын
Lol... I thought, I need much more preparation and leetcode practice 😂
@Amit6316-w6e
@Amit6316-w6e Жыл бұрын
Sir i want to ask something to you, I m a commerce student but I m very interested in coading is this better for me.?
@cloudtech5260
@cloudtech5260 Жыл бұрын
Yes. If you get in IT industry definitely it is good for you 👍
@abhishek7713
@abhishek7713 Жыл бұрын
😅 ye or exp walo ko puchenge 😅😅
@1313durgesh
@1313durgesh Жыл бұрын
we can also use Streams
@cloudtech5260
@cloudtech5260 Жыл бұрын
Yes
@PatelIndra
@PatelIndra Жыл бұрын
This program done by using only 1 for loop ..Guys ..We don't want take more than 1 for loop
@surajchougala
@surajchougala Жыл бұрын
I am having 2.8 years experience in java developer and what package should I need to ask
@cloudtech5260
@cloudtech5260 Жыл бұрын
Hi Suraj, it depends on the company, but the general rule is Average package = years of experience* 2 Good package = years of experience* 3 Best package = years of experience* 4 These values are general guidelines, some people can get even higher or lower packages. Best of luck 👍
@mriduljain8092
@mriduljain8092 Жыл бұрын
Sama banda interviewer accenture wali video me bhi tha..... How is this possible ?
@cloudtech5260
@cloudtech5260 Жыл бұрын
Hi Mridul, Mock interview 👍
@AdBoss12
@AdBoss12 Жыл бұрын
But in which app they are coding please can anyone tell i want to download that
@cloudtech5260
@cloudtech5260 Жыл бұрын
You can use eclipse for coding.
@AdBoss12
@AdBoss12 Жыл бұрын
@@cloudtech5260 thank you sir i can learn a lot from your videos
@zamanali713
@zamanali713 Жыл бұрын
Mazaak tha kya ye😊... It can easily be solved with time complexity of O(N).....with just one for loop....in javascript....Why to use so many for loops.....
@rathneshpolavarapu9628
@rathneshpolavarapu9628 Жыл бұрын
Even in 5lpa jobs asking to implement linkedlists how cognizant giving 9 lakhs for this question ❓ This is something looks fishy
@cloudtech5260
@cloudtech5260 Жыл бұрын
You can compare the packages offered before and after covid 19. Getting 9-10LPA in 2-3 years of experience is very easy in MNCs.
@prudhvi_reddy
@prudhvi_reddy Жыл бұрын
I think it is not a 9lpa interview 🙄...some fresher's hiring interview
@ranganath4110
@ranganath4110 Жыл бұрын
This is too easy I am fresher I am looking for a job I didn't get any chance
@hussainrizvi7316
@hussainrizvi7316 Жыл бұрын
this can be done in contant space and O(N ) time, this video tittle is only a clickbait ....
@pranavdambalkar5365
@pranavdambalkar5365 10 ай бұрын
int[] myArr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] processedArray = new int[myArr.length]; int left = 0; int right = myArr.length - 1; for (int i = 0; i < myArr.length; i++) { if (myArr[i] % 2 == 0) { processedArray[left] = myArr[i]; left++; } else { processedArray[right] = myArr[i]; right--; } } System.out.println(Arrays.toString(processedArray)); hope this helps :D
@sanketpoojari6057
@sanketpoojari6057 Жыл бұрын
How much scripted do you want it to be? CloudTech: Yes!!
@bharanRK
@bharanRK Жыл бұрын
Dude if you don't use time/space complexity.. as a factor in your coding.. you will never be able to crack top companies programming rounds
@KaustavOP
@KaustavOP Жыл бұрын
Is is on campus interview?
@cloudtech5260
@cloudtech5260 Жыл бұрын
This is a mock interview 👍
@pratika-prakhar
@pratika-prakhar Жыл бұрын
solution is not optimized? you are using two for loops and also using extra space. This can be done by O(n) time complexity and O(1) space complexity
@cloudtech5260
@cloudtech5260 Жыл бұрын
Yes. Correct. Will optimize the upcoming solutions. 👍
@greyhat6599
@greyhat6599 Жыл бұрын
Hey chill ! Although, optimizing the problem is always nice practice , but the main motive here is to solve the problem and not to optimize it.....☺️ And He is really doing it well ! I appreciate it !!💝❣️
@namanpatel7366
@namanpatel7366 Жыл бұрын
I had the same idea similar to what @GreyHat was emphasising. It improves our time complexity as well as space complexity but the only trade off will be maintaining the order of the numbers. //arrange the array in even numbers first, than odd numbers import java.util.*; class HelloWorld { public static void main(String[] args) { int[] numbers = {1,2,5,4,7,8,11,20}; // if the order of the elements in the array doesn't matter // we already have an idea about our expected result which is even numbers on the right and odd numbers on the left //lets take two pointer approach int i = 0; int j = numbers.length-1; while (i
@namanpatel7366
@namanpatel7366 Жыл бұрын
Some Similar problems to practice will be 1) Segregate 0s on the left and 1s on the right side from a given array. While traversing the array only once. int[] numbers = {1,0,1,1,0,0,1,0} 2) Segregate 0s on the left side, 1 in the middle and 2s on the right from a given array. int[] numbers = {1,2,1,1,0,0,2,2,0}
@sateesh9525
@sateesh9525 Жыл бұрын
It's fake call I think😂 for views, simple one and now a days every one using streams if u write like this they think u r not aware about latest coding skills
@ravikumark2023
@ravikumark2023 Жыл бұрын
Idhu interview? Adha na nambanum🌚
@Sayan_Shankhari
@Sayan_Shankhari Жыл бұрын
when will you stop using mod to get odd even, just check if last digit is in [0, 2, 4, 6, 8] or not 😂
@rakipalivela64
@rakipalivela64 Жыл бұрын
Bye bye, thank you 😂😂😂
@MrBkkrishna
@MrBkkrishna Жыл бұрын
if he IIT or IIM and they clear they give 10 laks not for everyone simply fooling around telling of money
@an_other_world
@an_other_world Жыл бұрын
And why was i recommended this KZbin?
@veereshj9421
@veereshj9421 Жыл бұрын
Lol no one gives you 9lpa for such questions
@rohankrishnani
@rohankrishnani Жыл бұрын
I don't think these are true interviews, the guy is simply faking it .
@cloudtech5260
@cloudtech5260 Жыл бұрын
Hi Rohan, Mock interview 👍
@avocadorable3695
@avocadorable3695 Жыл бұрын
same person taking interview in every company,,, lol
@cloudtech5260
@cloudtech5260 Жыл бұрын
This is mock interview with real-time questions.
@kartikrajput9880
@kartikrajput9880 Жыл бұрын
Kafi Faila hua business hai Control Majnu... Control
@susheelkumar291
@susheelkumar291 Жыл бұрын
Noob level max++
@ritwikbhar21
@ritwikbhar21 Жыл бұрын
Very bad solution. Why do you even need an extra array.
@SagarSingh-il7ui
@SagarSingh-il7ui Жыл бұрын
It can be solved in single pass without using auxiliary space as well. Let me know if anyone wants the code 😉
@cloudtech5260
@cloudtech5260 Жыл бұрын
Hi Sagar, Good day. Please paste the code in the comments section, it will be really helpful. Thanks. 👍
@SagarSingh-il7ui
@SagarSingh-il7ui Жыл бұрын
public class YtSolution { // {1,3,2,4,5,10,7,11,9,8} public static void main(String[] args) { int[] a = {1,3,2,4,5,10,7,11,9,8}; int i = 0; for(int j = 0;j
@xolo2617
@xolo2617 Жыл бұрын
@@SagarSingh-il7ui How will you maintain order then? question says you have to solve this in ascending order ? you need sorting here don't focus only one testcase try to think for all test cases
@extremeweirdness1528
@extremeweirdness1528 Жыл бұрын
Lol I wasn't asked a single coding question in the interview for genCnext and in my opinion don't join these companies also. You will spoil your career.
@abhijitzende7292
@abhijitzende7292 Жыл бұрын
import java.util.*; // Compiler version JDK 11.0.2 class EvenFirst { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int len = sc.nextInt(); int[] arr = new int[len]; for(int i=0;i
@cloudtech5260
@cloudtech5260 Жыл бұрын
Thanks Abhijit 👍
@easywaytostudy8061
@easywaytostudy8061 10 ай бұрын
Java code chalange kzbin.infoltgMz_nyZBE?si=jxae4Zp21gArbDwB
@gopalkannan4934
@gopalkannan4934 Жыл бұрын
Thank you
Infosys Java Coding Round
12:43
CloudTech
Рет қаралды 212 М.
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 8 МЛН
WHAT’S THAT?
00:27
Natan por Aí
Рет қаралды 14 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 13 МЛН
I solved 541 Leetcode problems. But you need only 150.
7:42
Sahil & Sarra
Рет қаралды 2,3 МЛН
Testing Mock Interview| Java Mock Interview For Freshers
29:17
RD Automation Learning
Рет қаралды 409 М.
Capgemini Java 8 Interview | Candidate rocked the interview
9:25
Solve Any Pattern Question With This Trick!
57:20
Kunal Kushwaha
Рет қаралды 2,3 МЛН
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 8 МЛН