yuvrajverma01 / 300-Questions-Coding

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

300 Questions-Code


Given an array arr of N integers. Find the contiguous sub-array(containing at least one number) which has the maximum sum and return its sum.

Input:
N = 5 arr[] = {1,2,3,-2,5}

Output:
9

int maxSubarraySum(int arr[], int n) {

    int current = 0;                      //This stores value of current elements
    int maximum = INT_MIN;                //The maximum value of a sub array is kept here
    for(int i=0; i<n; i++) {
        current = current + arr[i];       //Add arr[i] in current to store sum of next element
        if(current>maximum) {             //If current > maximum, store current in maximum
            maximum = current;             
        }
        if(current < 0) {                 //Edge Case
            current = 0;
        }
    }
    return maximum;
}

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

Input:
intervals = [[1,3],[2,6],[8,10],[15,18]]

Output:
[[1,6],[8,10],[15,18]]
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6].

Case 1:
          a ----------- b
start -------------------------- end

Case 2:
                a ----------------------------- b
start -------------------------- end

Case 3:
a ----------------------------- b
            start -------------------------- end

def mergeoverlappingintervals(arr, n):
    answer = []
    arr.sort()
    start = arr[0][0]
    end = arr[0][1]

    for i in range(1, n):
        # Case 1 - Start and End remains same
        if (arr[i][0]>=start and arr[i][1]<=end):
            continue
        # Case 2 - Start remains same but b becomes End
        elif (arr[i][0]>=start and arr[i][1]>=end and arr[i][0]<=end):
            end = arr[i][1]
        # Case 3 - a becomes Start but End remains same
        elif (arr[i][0]<=start and arr[i][1]<=end and arr[i][0]<=end):
            start = arr[i][0]
        else:
            answer.append([start, end])
            start = arr[i][0]
            end = arr[i][1]
    answer.append([start, end])
    return answer

Given an array a[] of size N which contains elements from 0 to N-1, you need to find all the elements occurring more than once in the given array.

Input:
N = 5 a[] = {2,3,1,2,3}

Output:
2 3

Step 1: First check all the values that are present in an array then go to that values as indexes and increment by the size of array. Step 2: Now check which value exists more than once by dividing with the size of array.

def printRepeating(arr, n):
 
    for i in range(0, n):
        index = arr[i] % n
        arr[index] += n
 
    for i in range(0, n):
        if (arr[i]/n) >= 2:
            print(i)

Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's, and return the matrix.

Input:
matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]

Input:
Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]

Step 1: Iterate through first column to check if it has 0 or not.

0 1 2 0
3
1

Step 2: Iterate through 2nd column. If any element is 0 in the matrix make the values at index 0 in first row and column.

0 1 2 0
3
1

Step 3: Traverse backwards and if the first row and column contains 0, set the value of arr[i][j] = 0.

0 1 2 0
3 4 5 2
1 3 1 5
def setZeroes(arr):
    row = len(arr)
    col = len(arr[0])
    #Flag is to check wether the first column has 0 or not
    flag = True               

    for i in range(row):
        if(arr[i][0] == 0):
            flag = False

        for j in range(1, col): 
            if(arr[i][j] == 0):
                arr[i][0] = arr[0][j] = 0
    
    for i in range(row-1, -1, -1):
        for j in range(col-1, 0, -1):
            if(arr[i][0] == 0 or arr[0][j] == 0):
                arr[i][j] = 0
        if flag == False:
            arr[i][0] = 0

    return arr

Given an integer numRows, return the first numRows of Pascal's triangle.

In Pascal's triangle, each number is the sum of the two numbers directly above it.

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Input:
n = 5

Output:
[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]

def pascalstriangle(n):
    flag = 1
    temp = []
    arr = []
    for i in range(n):
        temp = []
        for j in range(i+1):
            if(j==0 or i==0):
                flag = 1
                temp.append(flag)
            else:
                flag = flag*(i-j+1)//j
                temp.append(flag)
        arr.append(temp)
    return arr

Implement the next permutation, which rearranges the list of numbers into Lexicographically next greater permutation of list of numbers. If such arrangement is not possible, it must be rearranged to the lowest possible order i.e. sorted in an ascending order. You are given an list of numbers arr[ ] of size N.

Input:
N = 6 arr = {1, 2, 3, 6, 5, 4}

Output:
{1, 2, 4, 3, 5, 6}

Explanation: The next permutation of the given array is {1, 2, 4, 3, 5, 6}.

Step 1: Traverse the array backwards from n-2 and check which a[i] < a[i+1]
Step 2: If i < 0 then reverse the array
Step 3: Traverse backwards from n-1 till >i and check if a[j] > a[i]
Step 4: Swap the a[i] with a[j]
Step 5: Reverse the array after a[i]

vector<int> nextPermutation(int N, vector<int> arr){
    int i=0;
    int j = 0;
    N = arr.size();
    for(i=N-2; i>=0; i--) {
        if(arr[i] < arr[i+1]) {
            break;
        }
    }
    
    if(i<0) {
        reverse(arr.begin(), arr.end());
    } else {
        for(j = N-1; j>i; j--) {
            if(arr[j] > arr[i]) {
                break;
            }
        }
        swap(arr[i], arr[j]);
        reverse(arr.begin() + i + 1, arr.end());
    }
    return arr;
}

Given an array of integers. Find the Inversion Count in the array.

Inversion Count: For an array, inversion count indicates how far (or close) the array is from being sorted. If array is already sorted then the inversion count is 0. If an array is sorted in the reverse order then the inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j.

Input:
N = 5
arr[] = {2, 4, 1, 3, 5}

Output:
3

Explanation: The sequence 2, 4, 1, 3, 5 has three inversions (2, 1), (4, 1), (4, 3).

def mergeSort(arr, n):
    temp = [0]*n
    return _mergeSort(arr, temp, 0, n-1)

def _mergeSort(arr, temp, left, right):
    mid = 0
    count = 0

    if(right>left):
        mid = (right+left)//2
    
        count += _mergeSort(arr, temp, left, mid)
        count += _mergeSort(arr, temp, mid+1, right)

        count += merge(arr, temp, left, mid+1, right)
    return count

def merge(arr, temp, left, mid, right):
    i = left #Index for left subarray
    j = mid+1  #Index for right subarray
    k = left #Index for resultant merging array
    count = 0

    while((i<=mid) and (j<=right)):
        if arr[i]<=arr[j]:
            temp[k] = arr[i]
            k += 1
            i += 1
        else:
            temp[k] = arr[j]
            k += 1
            j += 1
            count = count + (mid-i)
    
    while (i<=mid-1):
        temp[k] = arr[i]
        k += 1
        i += 1
    while (j<=right):
        temp[k] = arr[j]
        k += 1
        j += 1
    for i in range(left, right+1):
        arr[i] = temp[i]
    return count

arr = [1, 2, 3]
n = len(arr)
print(mergeSort(arr, n))

You are given an array prices where prices[i] is the price of a given stock on the ith day.

You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.

Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.

Input:
prices = [7,1,5,3,6,4]

Output:
5

Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell.

The theory is try to sell out at max price and keep storing minimum and check the difference between the maximum and minimum.

arr = [3, 1, 4, 8, 7, 2, 5]

min = [3 or 8, 1 or 8, 4 or 8, 8 or 7, 7 or 5, 2 or 5, 5]

max = [8, 8, 8, 8, 7, 5, 5]

Step 1: Make minimum = arr[0] to store current minimum value of stock
Step 2: Put the arr[i] - minimum into a profit variable
Step 3: Then calculate maximum of minimum element and profit to find the maximum profit in a certain window

int maxProfit(vector<int>& arr) {
    int minimum = arr[0];
    int maximum = 0;
    int n = arr.size();
    for(int i=0; i<n; i++) {
        minimum = min(minimum, arr[i]);
        int profit = arr[i] - minimum;
        maximum = max(maximum, profit);
        
    }
    
    return maximum;
}

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).

You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.

Input:
matrix = [[1,2,3],[4,5,6],[7,8,9]]

Output:
[[7,4,1],[8,5,2],[9,6,3]]

Explanation:

Step 1: Make transpose of the matrix by swapping arr[i][j] with arr[j][i]
Step 2: Then horizontally shift the matrix
i. Run for loop from of i from 0 to n
ii. Run for loop from of j from 0 to n/2
Step 3: Then swap arr[i][n - 1 -j] with arr[i][j]

void rotate(vector<vector<int>>& arr) {
    int n = arr.size();
    for(int i=0; i<n; i++) {
        for(int j=i; j<n; j++) {
            swap(arr[i][j], arr[j][i]);
        }
    }

    for(int i=0; i<n; i++) {
        for(int j=0; j<n/2; j++) {
            swap(arr[i][n - 1 -j], arr[i][j]);
        }
    }
}

Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

Input:
x = 2.00000
n = 10

Output:
1024.00000

Explanation:

If power is even
210 = (2 x 2)5 = (4)5
(4)5 - now the power has become positive so,
x becomes x = x*(x)n-1

if n is even:
x = x*x n = n/2

if n is odd:
ans = ans*x; n = n-1

double myPow(double x, int m) {
    long long n = m;
    double ans = 1.0;

    if(n<0) {
        n = (-1)*n;
    }

    while(n) {
        if(n%2 == 0) {
            x = x*x;
            n = n/2;
        } else {
            ans = ans*x;
            n = n-1;
        }
    }

    if(m<0) {
        ans = 1/ans;
    }

    return ans;
}

The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.

Input:
nums = [2,2,1,1,1,2,2]

Output:
2

Explanation:

Step 1: This is Moore Voting Algorithm
Step 2: There are multiple blocks of elements where count becomes 0

Prefix                                                       Suffix
________ | ________ | ________ | ________ | ________
Step 3: If the element doesn't becomes majority in prefix, then it is bound to become majority in the last block i.e. Suffix.

def majorityElement(arr):
    ele = 0
    count = 0

    for i in range(len(arr)):
        if count==0:
            ele = arr[i]

        if arr[i] == ele:
            count += 1
        else:
            count -= 1
    
    return ele

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.

Input:
arr = [1 , 1, 1, 3, 3 , 2, 2, 2]

Output:
[1, 2]

Explanation:

Step 1: This is Boyre Moore Voting Algorithm
Step 2: As n/3 only gives 2 as maximum remainder so there must be at max 2 majority elements in an array that have counts greater tha n/3.
Step 3: Instead of ele now there will be num1, num2, c1, c2 to store two elements.

def majorityElement(arr):
    num1 = -1
    num2 = -1
    c1 = 0
    c2 = 0

    for i in range(len(arr)):
        if arr[i] == num1:
            c1 += 1
        elif arr[i] == num2:
            c2 += 1
        elif c1 == 0:
            num1 = arr[i]
            c1 = 1
        elif c2 == 0:
            num2 = arr[i]
            c2 = 1
        else:
            c1 -= 1
            c2 -= 1

    temp = []
    c1 = 0
    c2 = 0
    for i in range(len(arr)):
        if arr[i] == num1:
            c1 += 1
        if arr[i] == num2:
            c2 += 1
        
    if c1 > len(arr)//3:
        temp.append(num1)
    if (c2 > len(arr)//3) and (num1 != num2):
        temp.append(num1)
        
    
    return temp

.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




Rest Day! You have succesfully grinded for 50 days. Let's go king for another 50 days. You got this 👑.


.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




.

Input:


Output:


Explanation:

Step 1: Step 2: Step 3:




About

License:MIT License