View allAll Photos Tagged InterviewPrep

As the title says, we need to find the square root of a number. Let say the number is x, then Sqrt(x) is a number such that Sqrt(x) * Sqrt(x) = x. If the square root of a number is some decimal value, then we have to return the floor value of the square root.

Example

4

2

7

2

Approach(Pre-built functions)

The math library of C++ and lang.Math library of Java have the pre-built functions to return the square root of a number. We can apply floor() to avoid any decimal value.

Algorithm

 

- If the number is less than 2, return itself

- Call the sqrt() function

- Floor the value obtained

- Print the result

 

Implementation of Sqrt(x) Leetcode Solution

C++ Program

#include

using namespace std;

 

int mySqrt(int x)

{

if(x

 

www.tutorialcup.com/leetcode-solutions/sqrtx-leetcode-sol...

The problem Rotate List Leetcode Solution provides us a linked list and an integer. We are told to rotate the linked list to the right by k places. So if we rotate a linked list k places to the right, in each step we take the last element from the list and place it in from. We repeat this until we have done k number of these operations. Let's take a look at a few examples.

head = , k = 2

 

Explanation: Let's break the operation into 2 simple rotation operations. So, in the first step or move, we simply take the element from the end of the list and place it in front. So, the list becomes . Now, again we repeat the same operation making the list, . And hence the answer.

head = , k = 4

 

Explanation: Repeating the process 4 times result in the answer linked list. It can be better understood by looking at the image below.

 

Approach for Rotate List Leetcode Solution

The problem Rotate List Leetcode Solution states that you are given a linked list with an integer for rotation. This means that we need to rotate the list k places to the right. The problem can be understood by a simple operation of taking the elements from the end of the list and placing them in front. Since there is no way to efficiently remove an element from the end and place it in front. We need to think of any other way to perform the operation. If we observe, we can see that after performing k operations, k elements from the end are removed and are placed in front.

 

www.tutorialcup.com/leetcode-solutions/rotate-list-leetco...

Problem Statement

In this problem, we are given an array of integers. Also, we are allowed to perform a certain set of operations on this array. In one operation, we can increment " n - 1" (all elements except any one) elements in the array by 1.

 

We need to find the minimum number of operations required to make all array elements equal.

Example

Array = {1 , 2 , 3}

3

Array = {1 , 1 , 1}

0

 

Approach (Math)

In this problem, the difficulty is to choose the set of numbers you would like to increase by 1 to equal all the array elements. However, increasing 'N - 1' elements in the array is the same as decreasing one array element by 1. This is because we do not wish to find out what will be the value of all elements once they are equal, rather we are interested in finding the number of moves. Now, this is intuitive that since our operation is to decrease exactly one element in the array by 1, we need to convert all the elements in the array to the minimum element present in the array(As it doesn't need to be decreased any further).

Implementation for Minimum Moves to Equal Array Elements Leetcode Solution

C++ Program

#include

 

using namespace std;

 

int minMoves(vector nums) {

int mn = *min_element(nums.begin() , nums.end()) , moves = 0;

for(int &i : nums)

moves += i - mn;

return moves;

}

 

int main() {

vector nums = {1 , 2 , 3};

cout

 

www.tutorialcup.com/leetcode-solutions/minimum-moves-to-e...

Image free to use with credit to Ethereal Pathways and a dofollow link to etherealpathways.com/how-to-manifest-a-job-in-7-steps-att...

Want to learn some effective Tips to prepare for Campus Recruitment?

 

Then let's find out some ✨

 

🔖Practice for all types of interviews

 

🔖Dress to impress

 

🔖Ready with your research work.

 

🔖Work on your communication skills.

 

🔖Have a proper file for all your documents.

 

Now you are good to go!

 

Follow @humanresourceindia to know more human resource oriented tips, job updates and insights.

 

______________________

 

If you have any queries tell us in comments below 👇

 

#campusrecruitment #campusrecruitmenttraining #campus #recuritment #recruitmentagency #recruiter #recruiting #rectuit #interviewskills #interviewprep #interviewtips #interviewquestions #interview #interviews #interviewpreparation #interviewing #interviewoutfit #interviewready #tipsandtricks #preparations #resumeservices #resume #resumetemplate #humanresourcesmanagement #humanresourceindia #research #campusplacement #campusambassador #campuslife #campusplacements

1 3