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
import java.util.*; | |
public class ValidParenthesis { | |
public static void print(char str[],int pos,int len, | |
int open ,int close){ | |
if(close == len){ | |
System.out.println(str); | |
return; |
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
import java.util.*; | |
class Node{ | |
int data; | |
Node left; | |
Node right; | |
public Node(int data){ | |
this.data = data; | |
this.left = null; |
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
import java.util.*; | |
public class KthLargest { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
System.out.println("Enter the size of the array"); | |
int size = scan.nextInt(); |
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
import java.util.*; | |
public class SortedArrayPos { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
int minpos = -1 , maxpos= -1; | |
System.out.println("Enter the size of the array"); | |
int size = scan.nextInt(); | |
int [] arr = new int[size]; | |
for(int i=0;i<size;i++){ |
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
class Node { | |
int data; | |
Node left; | |
Node right; | |
public Node(int data){ | |
this.data = data; | |
this.left = null; | |
this.right = null; | |
} |
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
class Solution { | |
public boolean isAnagram(String s, String t) { | |
Map<Character,Integer> maps = new HashMap<>(); | |
Map<Character,Integer> mapt = new HashMap<>(); | |
for(int i=0;i<s.length();i++){ | |
if(maps.containsKey(s.charAt(i))){ | |
int val = maps.get(s.charAt(i)); | |
maps.put(s.charAt(i),val+1); |
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
class Solution { | |
public int binary(int[]nums,int low,int high,int target){ | |
if(low > high){ | |
return -1; | |
} | |
int mid = (low + high)/2; | |
if(nums[mid] == target){ | |
return mid; |
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
class Solution { | |
public int binary(int[]nums,int low,int high,int target){ | |
if(low > high){ | |
return -1; | |
} | |
int mid = (low + high)/2; | |
if(nums[mid] == target){ | |
return mid; |
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
class Solution { | |
public void merge(int[] nums1, int m, int[] nums2, int n) { | |
int[] result = new int[m+n]; | |
int i=0,j=0,z=0; | |
while(i<m && j<n){ | |
if(nums1[i] <= nums2[j]){ |
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
class Solution { | |
public int strStr(String haystack, String needle) { | |
int len = needle.length(); | |
for(int i=0;i<haystack.length()-len+1;i++){ | |
String substr = haystack.substring(i,i+len); | |
if(substr.equals(needle)){ | |
return i; | |
} | |
} |
NewerOlder