Last active
April 8, 2021 17:31
-
-
Save amustaque97/34fd04f09bc691c97561671f5123662f to your computer and use it in GitHub Desktop.
Upsolving Question asked in Interview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
Welcome to GDB Online. | |
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, | |
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. | |
Code, Compile, Run and Debug online from anywhere in world. | |
*******************************************************************************/ | |
public class Main | |
{ | |
public static void main(String[] args) { | |
int arr[] = { 900, 940, 950, 1100, 1500, 1800 }; | |
int dep[] = { 910, 1100, 1120, 1130, 1900, 2000 }; | |
int n = arr.length; | |
int count = 1, result = 1; | |
int i = 1, j = 0; | |
while (i < n && j < n) { | |
if (arr[i] <= dep[j]) { | |
count++; | |
i++; | |
} | |
else if (arr[i] > dep[j]) { | |
count--; | |
j++; | |
} | |
if (count > result) | |
result = count; | |
} | |
System.out.println(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment