₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,625 members, 8,512,828 topics. Date: Wednesday, 04 November 2026 at 05:01 AM

Toggle theme

Come And Solve This Problem - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Come And Solve This Problem (373 Views)

1 Reply

Come And Solve This Problem by turmacs(op): 1:49pm On Jan 18, 2025
You can try to solve this problem on your own with any programming language without looking at the solution. But if you can not solve it and would like to see a break down of the solution, I'll be posting it in the comments. Please don't bother using chatGpt because it can't solve this.

Problem Statement
Your a given an integer A, and two strings B and C as inputs.
Determine if it's possible to make B equal to C after performing any of the following operations between 0 and A times inclusive.

. Insert any one character at any position in B (possibly the beginning or end).
. Delete one character from B.
. Choose one character in B and replace it with another character.

Constraints
. Both B and C are strings of length between 1 and 500000, inclusive, consisting of lowercase English letters.
. C is always equal to 1. (That mean you can perform any of the operations at most once).

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Input Format
A
B
C
Output Format
If B can be made identical to C with at most K operations, ouput Yes. Otherwise, output No.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Input 1
1
ctf
cof
Sample Output 1
Yes
---------------------------------------------------------------------------------------------------------------------
Replacing the second character t of ctf with o converts ctf to cof in one operation.

Sample Input 2
1
jtg
jspo
Sample Output 2
No
-----------------------------------------------------------------------------
jtg cannot be become jspo in one operation

Sample Input 3
1
tsp
tp
Sample Output 3
Yes
-----------------------------------------------------------------------------------------------------------------------------------------
Deleting the second character s of tsp converts tsp to tp in one operation
Re: Come And Solve This Problem by turmacs(op): 2:49pm On Jan 18, 2025
smiley
Re: Come And Solve This Problem by airsaylongcome: 12:00am On Jan 19, 2025
Had to sign in to respond. Una really dey look ChatGPT less less o.

Algorithm:
1. Calculate Length Difference:
• Let lenB and lenC be the lengths of strings B and C , respectively.
• Compute length_diff = |lenB - lenC| .
• If length_diff > A , directly return “No” because it’s impossible to equalize the strings with A or fewer operations.

2. Count Mismatched Characters:
• Compare the characters of B and C for the overlapping part min(lenB, lenC).
• Count the number of mismatched characters, mismatch_count.

3. Compute Total Operations Required:
• To make B equal to C , the total operations required are:
total_ops = mismatch_count + length_diff
• If total_ops <= A , output “Yes”.
• Otherwise, output “No”.
1 Reply

Come And Solve This Coding Problem • Programmers In The House Pls Come In And Solve My Hassle • Please Help Me Solve This Problem In C++ • 2 • 3 • 4

cm2 box • Port Harcourt Programmers Please Help For Availabile Training Space • Please Help:i Need A Expert Programmer