Problem Statement:

You are given three string inputs. The third is a result of interweaving the two string inputs. Interweaving means that the characters of the two inputs string can jumbled in such way that the


This problem involves exploring different possibilities of mixing and matching the characters of…

Problem Statement:

In this problem you are three inputs: An orgchart , which is n-ry tree, and two repartees part of the organization.

The orgchart is a multi-level tree typical of an organisation where the leaves of a nodes are reporting to the manager root node.

You have to find…

  1. Use recursion to reach the end of the list.
  2. Once in the end return head, but move the pointer to prev.
  3. keeping a prev will help when the call reaches the last but one stack.
  4. keep changing pointer curr->next to prev node and returning the head.

There are three possible solutions to this.

  1. Using DP, cascading.
  2. Backtracking.
  3. Use Bitset method.

DP, cascading solution

use the idea of solving existing solved subset. Like adding a additional number to the existing subset starting with an empty subset”


next number is 1:


next number is 2:



similarily for other numbers in the array.


class Program {
public static List<List<Integer>> powerset(List<Integer> array) {
List<List<Integer>> subsets =new ArrayList<>();
subsets.add(new ArrayList<>());

subset(subsets,array,0 );
return subsets;
private static List<List<Integer>> subset(List<List<Integer>> lists,List<Integer> array, int val){

if(val == array.size()){
return lists;
List<Integer> temp =null;
List<List<Integer>> res = new ArrayList<>();
for(List list : lists){

temp = new ArrayList<>(list);

return subset(lists,array,val+1);


Backtracking Solution:


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store