Professional Documents
Culture Documents
19bcd7246 Assignment4 L27+L28+L31+L32
19bcd7246 Assignment4 L27+L28+L31+L32
SLOT : L27+L28+L31+L32
ASSIGNMENT NUMBER : 04
1. You are given a string s and an array of strings words of the same length.
Return all starting indices of substring(s) in s that is a concatenation of each
word in words exactly once, in any order, and without any intervening
characters.You can return the answer in any order.
Example 1:
Input: s = "barfoothefoobarman", words = ["foo","bar"]
Output: [0,9]
Explanation: Substrings starting at index 0 and 9 are "barfoo" and "foobar"
respectively.
The output order does not matter, returning [9,0] is fine too.
Example 2:
Input: s = "wordgoodgoodgoodbestword", words =
["word","good","best","word"]
Output: []
Example 3:
Input: s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
Output: [6,9,12]
CODE
import java.util.*;
class Question1
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String S = scan.next();
int n = scan.nextInt();
ArrayList<String> words =
new ArrayList<>();
for(int i=0;i<n;i++){
String w = scan.next();
words.add(w);
}
ArrayList<Integer> indices = Substring(S, words);
System.out.println(indices);
scan.close();
}
public static ArrayList<Integer>
Substring(String A, final List<String> B)
{
}
return res;
}
}
OUTPUT
Test Case-1
Test Case-2
Test Case-3
2. Word Problem
Get a matrix from the user. Pick a minimum of one character from one row and
create the word. If the guessed word abides to the rule return 1 else 0.
Example :
Given board =
[
["ABCE"],
["ESFC"],
["XDEE"]
]
AXE Output : 1
DOG Output : 0
BED Output : 1
CAT Output : 0
BASE Output: 1
CODE
import java.util.*;
class Main
{
static HashSet<String> set;
static void Func(String st,int i,String temp){
if(i>=st.length()){
set.add(temp);
return;
}
Func(st,i+1,temp+st.charAt(i));
Func(st,i+1,temp);
}
public static String sortString(String Str_input)
{
list.add(str);
}
String st="";
for(int i=0;i<list.size();i++){
st+=list.get(i);
}
st=sortString(st);
else
System.out.println("Output : 0");
}
}
}
OUTPUT