I am a Btech. Compter Science Engineering Student. I am actively learning the new concepts and new upcoming technologies.
Narula Institute of Technology 2024
My Stats
EXP gained
12839
Level
7 (Expert)
Community stats
Discussions
0
1
Know more
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
213
Total problems solved
124
Easy
84
Moderate
5
Hard
0
Ninja

Current streak:

0 days

Longest streak:

9 days

Less

More

Achievements
8
Ronin
Topics
Stacks & Queues
Sorting
+ 6 more
2
Samurai
Topics
Strings
Arrays
Discussions
Striver Soloution in JAVA
Interview problems

import java.util.*;

public class Solution {

public static Boolean isLeaf(TreeNode root) {

return (root.left == null) && (root.right == null);

}

public static void addLeftBoundary(TreeNode root, ArrayList<Integer>res)

{

TreeNode cur = root.left;

while (cur != null) {

if (cur.left != null) cur = cur.left;

else cur = cur.right;

}

}

public static void addRightBoundary(TreeNode root, ArrayList<Integer>res)

{

TreeNode cur = root.right;

ArrayList < Integer > tmp = new ArrayList < Integer > ();

while (cur != null) {

if (cur.right != null) cur = cur.right;

else cur = cur.left;

}

int i;

for (i = tmp.size() - 1; i >= 0; --i) {

}

}

public static void addLeaves(TreeNode root, ArrayList < Integer > res) {

if (isLeaf(root)) {

return;

}

if (root.left != null) addLeaves(root.left, res);

if (root.right != null) addLeaves(root.right, res);

}

public static List<Integer> traverseBoundary(TreeNode root){

// Write your code here.

ArrayList<Integer>ans=new ArrayList<>();

return ans;

}

}

Published On 16-Oct-2023
44 views
2 replies
Simple Recursion
Interview problems

public class Solution

{

public static int minValue(Node root) {

// Write your code here.

if(root==null)

{

return -1;

}

if(root.left!=null)

{

return minValue(root.left);

}

else return root.data;

}

}

Published On 01-Oct-2023
134 views
0 replies
java code using backtracking
Interview problems

import java.util.* ;

import java.io.*;

public class Solution {

public static  void rec(int indx,ArrayList<ArrayList<Integer>> ans,ArrayList<Integer> arr)

{

if(indx==arr.size())

{

ArrayList<Integer> temp=new ArrayList<>();

for(int i:arr)

{

}

}

else

{

for(int i=indx;i<arr.size();i++)

{

swap(i,indx,arr);

rec(indx+1, ans, arr);

swap(i,indx,arr);//backtracking

}

}

}

public static void swap(int a,int b,ArrayList<Integer> arr)

{

Collections.swap(arr, a, b);

}

static ArrayList<ArrayList<Integer>> permutations(ArrayList<Integer> arr, int size) {

// Write your code here.

ArrayList<ArrayList<Integer>> ans=new ArrayList<>();

rec(0,ans,arr);

return ans;

}

}

Published On 09-Sep-2023
36 views
0 replies
Java Solution
Interview problems

class Pair

{

int hd;

BinaryTreeNode node;

public Pair(int hd,BinaryTreeNode node)

{

this.hd=hd;

this.node=node;

}

}public class Solution {

public static ArrayList<Integer> getTopView(BinaryTreeNode root) {

// Write your code here.

ArrayList<Integer> list=new ArrayList<>();

if(root==null) return list;

Map<Integer,Integer> map=new TreeMap<>();

while(!q.isEmpty())

{

Pair curr=q.poll();

if(!map.containsKey(curr.hd))

{

map.put(curr.hd,curr.node.val);

}

if(curr.node.left!=null)

{

}

if(curr.node.right!=null)

{

}

}

for(Map.Entry<Integer,Integer> entry:map.entrySet())

{

}

return list;

}

}

Published On 04-Aug-2023
66 views
0 replies
using java
Interview problems

import java.util.*;

import java.io.*;

public class Solution{

static ArrayList<Integer> nextSmallerElement(ArrayList<Integer> arr, int n){

// Write your code here.

Stack<Integer> q=new Stack<>();

q.push(-1);

int curr=0;

ArrayList<Integer> al=new ArrayList<>();

for(int i=n-1;i>=0;i--)

{

curr=arr.get(i);

while(curr<=q.peek())

{

q.pop();

}

q.push(curr);

}

Collections.reverse(al);

return al;

}

}