--------------------------------------------------------------------------------------------------------
Problem 1 :
 Link to question : https://leetcode.com/problems/two-sum/
 Solution : 
 In Python 3:
 class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        for i in range(len(nums)):
            for j in range(i+1,len(nums)):
                sum=nums[i]+nums[j]
                if sum==target:
                    return i,j
        return []
--------------------------------------------------------------------------------------------------------
Problem 2 : 
 Link : https://leetcode.com/problems/reverse-linked-list/
 Solution 
 CPP
 ListNode* reverseList(ListNode* head) {
        if( head==NULL || head->next==NULL){
            return head;
        }
        
        ListNode* newnode=reverseList(head->next);
        head->next->next=head;
        head->next=NULL;
        return newnode;
        
        
 }
 
 ------------------------------------------------------------------------------------------------------------
 Problem 3:
 Link : https://leetcode.com/problems/first-bad-version/
 solution 
 CPP
 int firstBadVersion(int n) {
    int low=1,high=n;
    int mid=0;;
    while(low<=high){
    mid=low+(high-low)/2;
    if(low==high) return mid;

        if(isBadVersion(mid))
            high=mid;
        else
            low=mid+1;
    }
    return-1;
}

---------------------------------------------------------------------------------------------------------------
Problem 4:
link : https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
solution 
CPP

 int maxProfit(vector<int>& prices) {
        int lsf = INT_MAX; 
        int op = 0; 
        int pist = 0;
        
        for(int i = 0; i < prices.size(); i++){
            if(prices[i] < lsf){
                lsf = prices[i];
            }
            pist = prices[i] - lsf;
            if(op < pist){
                op = pist;
            }
        }
        return op;
        
    }

---------------------------------------------------------------------------------------------------------------
Problem 704:
link : https://leetcode.com/problems/binary-search/
solution 
C



int search(int* nums, int numsSize, int target){
     if (numsSize == 1 && nums[0] == target)
        return 0;
    
    int min , max , mid ;
    min=0;
    max=numsSize-1;
    
    while(min<=max)
    {   mid=(min+max)/2;
        if(nums[mid]==target)
        {   
            // printf("%d",target);
            return mid;
           
        }
        else if(target > nums[mid])
        {
            min=mid+1;
        }
        else
        {
            max=mid-1;
        }
    }
    return -1;
}

----------------------------------------------------------------------------------------------------------------------------
Problem 42:
link : https://leetcode.com/problems/trapping-rain-water/
solution 
java

import java.util.*;
    
    
class Solution {
    public int trap(int[] height) {
       int result = 0;
 
    if(height==null || height.length<=2)
        return result;
 
    int left[] = new int[height.length];
    int right[]= new int[height.length];
 
    //scan from left to right
    int max = height[0];
    left[0] = height[0];
    for(int i=1; i<height.length; i++){
        if(height[i]<max){
            left[i]=max;
        }else{
            left[i]=height[i];
            max = height[i];
        }
    }
 
    //scan from right to left
    max = height[height.length-1];
    right[height.length-1]=height[height.length-1];
    for(int i=height.length-2; i>=0; i--){
        if(height[i]<max){
            right[i]=max;
        }else{
            right[i]=height[i];
            max = height[i];
        }
    }
 
    //calculate totoal
    for(int i=0; i<height.length; i++){
        result+= Math.min(left[i],right[i])-height[i];
    }
 
    return result;
}
    }




















































