Skip to content

Instantly share code, notes, and snippets.

@iamgauravbisht
Created December 24, 2023 20:59
Show Gist options
  • Save iamgauravbisht/a317e9c227fd07cace1b1322df6c6fe5 to your computer and use it in GitHub Desktop.
Save iamgauravbisht/a317e9c227fd07cace1b1322df6c6fe5 to your computer and use it in GitHub Desktop.
Quadratic ->O(n^2) Space Time Complexity
package spaceTimeComplexity;
public class Quad {
public static void main(String[] args) {
int[] arr= new int[]{1,2,3,4,5,6,7,8,9,0,4,10};
int target=10;
// Find the pair of Values in Array whose sum is equal to target
for(int i=0; i<arr.length;i++){ // Time C. -> O(n)
for (int j= i+1; j<arr.length;j++){ // Time C. ->O(n) times O(n) -> O(n^2)
if(arr[i]+arr[j]==target){
System.out.println("Pair :" + arr[i] + " " + arr[j] );
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment