Character Formation Check
Determine if the second string STR2
can be constructed using characters from the first string STR1
. Both strings may include any characters.
Input:
The first line contains an integer T
, the number of test cases.
For each test case:
The first line contains the string STR1
.
The second line contains the string STR2
.
Output:
For each test case, return "YES"
if STR2
can be formed from the characters of STR1
, otherwise return "NO"
.
Example:
Input:
STR1 = "codingninjas", STR2 = "sing"
Output:
"YES"
Explanation:
The second string, "sing", can be formed using characters "s", "i", "n", "g" from the first string "codingninjas".
Constraints:
1 ≤ T ≤ 100
1 ≤ |STR1|, |STR2| ≤ 1000
- Time Limit: 1 sec
Note:
There's no need to print the output. Implement the function that returns the expected results.

AnswerBot
4mo
Check if second string can be formed using characters from the first string.
Iterate through each character in STR2 and check if it exists in STR1.
Use a hashmap to store the frequency of characters in ...read more
Help your peers!
Add answer anonymously...
Nagarro Technical Trainee interview questions & answers
A Technical Trainee was asked Q. Detect and Remove Loop in Linked List For a given singly linked list, identify i...read more
A Technical Trainee was asked Q. Trapping Rainwater Problem Statement You are given an array ARR of long type, wh...read more
A Technical Trainee was asked Q. Spiral Order Traversal of a Binary Tree Given a binary tree with N nodes, your t...read more
Popular interview questions of Technical Trainee
A Technical Trainee was asked Q1. Detect and Remove Loop in Linked List For a given singly linked list, identify i...read more
A Technical Trainee was asked Q2. Trapping Rainwater Problem Statement You are given an array ARR of long type, wh...read more
A Technical Trainee was asked Q3. Spiral Order Traversal of a Binary Tree Given a binary tree with N nodes, your t...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

