My Stats
EXP gained
4414
Level
5 (Champion)
Community stats
Discussions
0
0
Know more
59
Total problems solved
44
Easy
14
Moderate
1
Hard
0
Ninja

Current streak:

0 days

Longest streak:

3 days

Less

More

Achievements
2
Ronin
Topics
Arrays
Discussions
simple java solution
Interview problems

public static boolean subsetSumToK(int n, int k, int arr[]){

// Write your code here.

boolean dp[][]=new boolean[n+1][k+1];

for(int i=0;i<=n;i++)

{

dp[i][0]=true;

}

for(int i=1;i<=n;i++)

{

for(int j=1;j<=k;j++)

{

if(j>=arr[i-1])

{

dp[i][j]=dp[i-1][j]||dp[i-1][j-arr[i-1]];

}

else

{

dp[i][j]=dp[i-1][j];

}

}

}

return dp[n][k];

}

Published On 10-Oct-2023
157 views
0 replies
java solution

public static void insertionSort(int[] arr, int size) {

//Your code goes here

for(int i=1;i<size;i++)

{

int x=arr[i];

int j=i-1;

while(j>=0&&arr[j]>x)

{

arr[j+1]=arr[j];

j--;

}

arr[j+1]=x;

}

}

Published On 15-Jul-2023
39 views
0 replies
Simple java Solution

public static ArrayList<Integer> zigzagTreeTraversal(TreeNode<Integer> root)

{

//    Write your code here.

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

boolean flag=false;

while(ll.size()>0)

{

int n=ll.size();

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

for(int i=0;i<n;i++)

{

root=ll.poll();

if(root.left!=null)

{

}

if(root.right!=null)

{

}

}

if(flag==false)

{

flag=true;

}

else

{

Collections.reverse(al);

flag=false;

}

}

return ans;

}