Update appNew update is available. Click here to update.
About
KCG College of Technology 2022
My Stats
EXP gained
yellow-spark
3572
Level
5 (Champion)
Community stats
Discussions
0
Upvotes
0
Know more
46
Total problems solved
35
Easy
11
Moderate
0
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

3 days

Less

More

Achievements
2
Ronin
Topics
Arrays
Hash Table
Discussions
Java Easy O(N) Approach
Interview problems

public static int isSorted(int n, int []a) {

        // Write your code here.

    

        for(int i=0;i<n-1;i++){

            int j=i+1;

            if(a[i]>a[j]){

                return 0;

            }

        }

        return 1;

    }

profile
Lakshmana kumar
Published On 23-Oct-2023
58 views
0 replies
0 upvotes
Java O(N) Easy Solution
Interview problems

public class Solution {

    public static int[] getSecondOrderElements(int n, int []a) {

        // Write your code here.

        int j=n-1;

        int small =Integer.MAX_VALUE;

        int large = -1;

        int second_large =-1;

        int second_small =Integer.MAX_VALUE;

        for(int i=0;i<=n/2;i++){

            small = Math.min(small , Math.min(a[i],a[j]));

            large = Math.max(large , Math.max(a[i],a[j]));

            j--;

        }

        for(int k=0;k<n;k++){

            if(a[k]!=large){

                second_large = Math.max(second_large,a[k]);

            }

            if(a[k] !=small){

                second_small = Math.min(second_small,a[k]);

            }

 

        }

        int[] arr = {second_large,second_small};

        return arr;

 

    }

}

profile
Lakshmana kumar
Published On 23-Oct-2023
61 views
0 replies
0 upvotes
Java Easy 0(n/2) solution approach using two pointer
Interview problems

import java.util.* ;

import java.io.*; 

 

public class Solution {

 

    static int largestElement(int[] arr, int n) {

        int i=0;

        int j=n-1;

        int high=0;

        while(j>i){

            high = Math.max(high, Math.max(arr[i],arr[j]));

            i++;

            j--;

        }

        return high;

 

    }

}

profile
Lakshmana kumar
Published On 23-Oct-2023
57 views
0 replies
0 upvotes