<div dir="ltr" style="text-align: justify;" trbidi="on">Recently ;I have attended one ;Hackathon ;event organized by the Amazon in the Delhi. In this event I have face two technical problems as below.</p>
<ol style="text-align: left;">
<li><b>Permutations of String ;</b></li>
<li><b>Product Maximization Problem</b></li>
</ol>
<p>
There is one of two problems I have face in the Hackathon Delhi in the amazon hiring process.<br />
<b><br />
</b> <b>Problem:</b></p>
<p>Given a <b>set of characters</b> and a positive integer <b>k</b>, print all possible strings of length <b>k</b> that can be formed from the given set in sorted order.</p>
<div align='center' id="ads-id"></div>
<p>
<b>Input format:</b></p>
<p>First line contains the number of characters.</p>
<p>Second line contains the characters separated by space. Assume the characters are in sorted order and all in lower case.</p>
<p>Third line contains <b>k</b>.</p>
<p><b>SAMPLE INPUT </b><br />
2<br />
a b<br />
3<br />
<b>SAMPLE OUTPUT </b><br />
aaa<br />
aab<br />
aba<br />
abb<br />
baa<br />
bab<br />
bba<br />
bbb</p>
<p><b>Solution:</b></p>
<pre class="highlight">package com.dineshonjava.algo;

import java.util.Scanner;

public class StringPermutation {

 private static Scanner sc;

 public static void main(String[] args) {
 sc = new Scanner(System.in);
 int N = sc.nextInt();
 String [] charArray = new String [N];
 for(int i = 0; i <; N ; i++){
 charArray [i] = sc.next();
 }
 int k = sc.nextInt();
 calculatePermutations(k, charArray, "");
 }
 
 private static void calculatePermutations(final int k, final String[] charArray, final String currentWord) {
 if (k == 0) {
 System.out.println(currentWord);
 } else {
 for (int i = 0; i <; charArray.length; i++) {
 calculatePermutations(k - 1, charArray, currentWord + charArray[i]);
 }
 }
 }
}

</pre>
<p>
Now run this application:</p>
<p>Go to command prompt or go to any IDE like eclipse or STS and first compile this java file and then run it.</p>
<p>>;Java StringPermutation <br />
2<br />
a b<br />
3</p>
<p>Output as below:<br />
aaa<br />
aab<br />
aba<br />
abb<br />
baa<br />
bab<br />
bba<br />
bbb</p>
<p>
Another <b><a href="https://dineshonjava.com/2016/08/product-maximization-problem-in-java.html">second question</a></b> was one of the two questions is <b><a href="https://dineshonjava.com/2016/08/product-maximization-problem-in-java.html">Product Maximization</a>.</b></p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/spring-boot-with-spring-mvc-application/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/product-maximization-problem-in-java/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '134'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…