---
# System prepended metadata

title: Aryan

---

# Aryan


```javascript=

// write a fn that'll return the second largest element of an array

fun(arr,n){
  Array.sort(arr);
  System.out.println(arr[n-2]);
  
}

   

fun(arr,n){
    int k=0;
    int l=0;
     for(int=0;i<n;i++){
         if(a[i] > k){
         k=a[i];
         }
     }
     
     for(int=0;i<n;i++){
         if((a[i] > l) &&  (a[i]!=k)){
         l=a[i];
         }
     }
  
   System.out.println("second larget is" + l); 
}


// sortedArr = [1,2,3,4,5,8,9]
// rotatedSortedArr = [8,9,1,2,3,4,5]
// k = 1
// return 2

function findindex(arr, k) {
    int n= arr.length;         // n is a length of an array
    int l=0                   //l is first element of array
    int r=n-1;                // r is last element of array     
    int m=0
    while(l<=r){
       m=(l+r)/2;                // m is a mid 
       if(k==arr[m]){
       System.out.println( "required element is" + m );
       }
           if(arr[l] <= arr[m]){
               if(k>= arr[l] && k<arr[m]){
               r =m-1;
               }
               else{
               l = m+1;
               }
            }
            else{
                if(k>arr[m] && k<=arr[r]){
                l= m+1;
                }
                else{
                r=m-1;
                }
            }           
     }   
   }
   
   
// n stairs
// 3
// [1,1,1] [2, 1] [1,2] => 3
// 2  [2] [1,1]
// 4   [1,2,1] [1,1,2] [2,2] [2,1,1]
function getNtop(n) {
   if (n == 0 || n== 1){
       return 1;}
   else if(n == 2){
       return 2;}
   else
     return (getNtop(n-2) + getNtop(n-1));

}

// 6







```