Skip to content

Instantly share code, notes, and snippets.

View anjansrivathsav's full-sized avatar
:octocat:
Focusing

anjansrivathsav anjansrivathsav

:octocat:
Focusing
  • mississauga , canada
View GitHub Profile
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;
@anjansrivathsav
anjansrivathsav / Symmetric.java
Created August 10, 2023 01:32
Symmetric tree left and right
import java.util.*;
class Node{
int data;
Node left;
Node right;
public Node(int data){
this.data = data;
this.left = null;
@anjansrivathsav
anjansrivathsav / KthLargest.java
Created August 10, 2023 01:07
Kth Largest value in array
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();
@anjansrivathsav
anjansrivathsav / SortedArrayPos.java
Created August 9, 2023 02:32
Sorted Array find target value min and max position
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++){
@anjansrivathsav
anjansrivathsav / Tree.java
Created August 5, 2023 23:17
Inorder , preorder and post order
class Node {
int data;
Node left;
Node right;
public Node(int data){
this.data = data;
this.left = null;
this.right = null;
}
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);
@anjansrivathsav
anjansrivathsav / searchInsertPosition.java
Created August 5, 2023 20:41
Search Insert Position
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;
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;
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]){
@anjansrivathsav
anjansrivathsav / firstOccurance.java
Created August 2, 2023 02:15
index of First Occurance
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;
}
}