Computer Science, asked by otroligash, 3 days ago

Write a Java program : String Permutations You are given two strings 'X' and 'Y, each containing at most 1,000 character.
Write a program that can determine whether the characters in the first string x can be rearranged to form the second string 'Y'.
The output should be "yes" this is possible and "no" if not.
Input Specification:
input1: the string 'X'
input2: the string 'Y'
Output Specification:
Return "yes" or "no" accordingly.
Example 1:
input1: zbk
input2: zkb
Output: yes
Explanation: You can rearrange zbk to be zkb (by switching the k and the
b). Hence the output is "Yes".
Example 2:
input1: Mettl
input2: Coding
Output: no​

Answers

Answered by gangasagerkamthekar2
29

Answer:

Given two strings str1 and str2, check if str2 can be formed from str1

Example :

Input : str1 = geekforgeeks, str2 = geeks

Output : Yes

Here, string2 can be formed from string1.

Input : str1 = geekforgeeks, str2 = and

Output : No

Here string2 cannot be formed from string1.

Input : str1 = geekforgeeks, str2 = geeeek

Output : Yes

Here string2 can be formed from string1

as string1 contains 'e' comes 4 times in

string2 which is present in string1.

Explanation:

PLZ MARK ME AS brainliest Ans

Answered by vishakasaxenasl
0

Answer:

The following program will perform the desired function:

string1 = list(input())

string2 = list(input())

count = 0

for i in range(len(string2)):

  if(string2[i] in string1):

    count +=1

if(count == len(string2)):

 return("yes")

else:

 return("no")

Successful Test Cases

 Example 1:

input1: zbk

input2: zkb

Output: yes

Example 2:

input1: Mettl

input2: Coding

Output: no​

Explanation:

  • First, we create two variables named string1 and string2 for taking the input from the user.
  • count variable will count the number of occurrences of string2 characters in string1
  • for loop is used to iterate over string2 and to compare string1 with string2.
  • If we get a count value equal to the length of string2, it means that string1 can be modified to make string2.

#SPJ3

Similar questions