Open in app

Sign In

Write

Sign In

Anita
Anita

8 Followers

Home

About

Nov 6, 2020

Java program to find who reaches first to the destination in a 2-dimensional array.

Given a 2-dimensional array where ‘s’ stones and ‘p’ people are present on its grids, you need to find who reaches the destination grid first when people can move only left, right, top, bottom and can’t move to a grid where the stone is placed. Approach : Depth First Search!! …

Interview Questions

1 min read

Interview Questions

1 min read


May 14, 2020

Program to find all possible smart arrays that can be constructed using a string of digits.

Program to find all possible smart arrays that can be constructed using a string of digits. A smart array is an array where if we remove spaces among integers, it becomes the same string from which it has been created. Also, a smart array should not have any leading zeroes. …

Java

2 min read

Java

2 min read


Apr 20, 2020

Program to find k-th Lexicographical String from all Happy Strings of length n in Java

Program to find k-th Lexicographical String from all Happy Strings of length n in Java A happy string is a string that: consists only of letters of the set ['a', 'b', 'c']. s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed). class MainProgram{ private String getHappyString(int n, int k) { char[] arr = {'a', 'b', 'c'}; String res=""; List<String> list=new ArrayList<>(); generatePerm(arr, n, res, list); if(list.size() >= k) res=list.get(k-1); return res; } private void generatePerm(char[] arr, int n, String res, List<String> list){ if(n == 0){ list.add(res); return; } for(int i=0; i<arr.length; i++){ if(res == "" || res.charAt(res.length()-1) != arr[i]){ String pre=res+arr[i]; generatePerm(arr, n-1, pre, list); } } }

Coding

1 min read

Program to find k-th Lexicographical String from all Happy Strings of length n in Java
Program to find k-th Lexicographical String from all Happy Strings of length n in Java
Coding

1 min read

Anita

Anita

8 Followers

Software Developer

Following
  • Piotr Gaczkowski

    Piotr Gaczkowski

  • Pratik Bhandari

    Pratik Bhandari

  • Ev Williams

    Ev Williams

  • Bret Cameron

    Bret Cameron

  • palak agarwal

    palak agarwal

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech