Hey guys, Today is day 40 of the 100 Days to** LinkedIn Challenge.**
Free For Kindle Readers
If you are Preparing for your Interview. Even if you are settled down in your job, keeping yourself up-to-date with the latest **Interview Problems **is essential for your career growth. Start your **prep **from Here!
Last month, I have been researching to find out the Frequently asked problems from these Companies. I have compiled **100 **of these questions, I am not promising you that you will get these questions in your interview but I am confident that most of these “interview questions” have similar logic and employs the same way of thinking from these set of challenges.
Before we move on to the first problem, If you are wondering why I chose LinkedIn, Yahoo and Oracle over FAANG are because I have completed a challenge Focusing on Amazon and Facebook Interview.
Given an array nums
with n
objects colored red, white, or blue, sort them in-placeso that objects of the same color are adjacent, with the colors in the order red, white, and blue.
Here, we will use the integers 0
, 1
, and 2
to represent the color red, white, and blue respectively.
Follow up:
O(1)
constant space?Input: nums = [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
Input: nums = [2,0,1]
Output: [0,1,2]
FollowHouse of Codes_ for keeping up to date in the programming interview world._
class Solution {
public void sortColors(int[] nums) {
int count0=0, count1=0, count2=0;
for(int i=0; i<nums.length; i++){
if(nums[i]==0){count0++;}
else if(nums[i]==1){count1++;}
else if(nums[i]==2){count2++;}
}
for(int i=0; i<nums.length; i++){
if(i<count0){nums[i]=0;}
else if(i<count0+count1){nums[i]=1;}
else {nums[i]=2;}
}
}
}
#software-development #interview #coding #programming #java