Yes we can save two numbers at one place by using simple mathematical formula.
The formula :
dividend=divisor*quotient+remainder
Yes we can save two numbers at one place by using simple mathematical formula.
The formula :
dividend=divisor*quotient+remainder
Step 1 :
Reverse the first k elements.
Step 2:
Reverse the k+1 to n-1 elements.
Step 3:
Reverse the whole array.
Prefect!!!
Example :
arr=[1,2,3,4,5] , k=2
expected output : [3,4,5,1,2]
step 1:
[2,1,3,4,5]
step 2:
[2,1,5,4,3]
step 3:
[3,4,5,1,2]
Got it!
To check for the rotation count in a sorted array :
we can check the index of the least element :
the index is the rotation count of the array.
For example :
[2,3,4,1]
index of 1 is 4, therefore rotation count is 4 to the right.
To count the digits in a factorial we must seek some optimization as you might also understand that getting all the product and storing the...