Click here to Skip to main content
15,441,629 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
You are provided a two lists named list a and list b, return Minimum number of 
manipulation needed to change list a into list b you are allowded to perfrom insert, 
remove and replace operation

Input: list a: {1, 2, 3, 5}, list b: {1, 4, 3}

Output: 2 as two operation are needed you need to replace Integer 2 with 4 and need to 
remove integer 5 from list an in order to make it as similar to list b


Give me the idea to solve this problem.


What I have tried:

what is the best method to tacle this problem soluton. If anyone had an idea then share me to solve me this problem.
Posted
Updated 1-Sep-21 5:04am
v3
Comments
Richard Deeming 1-Sep-21 8:47am     CRLF
Your homework is set to test what you have learned. Unless you are taking a course in how to manipulate strangers into doing your work for you, you need to do this assignment yourself. If you genuinely don't know where to start, then talk to your teacher. That's what they're paid for.

Sorry, this site does not provide code to order. You need to make an effort to solve the problem yourself.
 
Share this answer
 
The code is up to you, but I'd probably start with a breadth-first search in a ternary tree whose branches are

1. advance to the next element (only if the elements match)
2. erase the element in the first array (only if the elements don't match)
3. insert an element in the first array that matches the one in the second array
4. replace the element in the first array with the one in the second array

I'm not claiming that this is optimal, or even correct, so you need to come up with some difficult test cases and check the results by hand.
 
Share this answer
 
v2
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Quote:
what is the best method to tacle this problem soluton. If anyone had an idea then share me to solve me this problem.

The best method is the one you device after trying simple non optimal methods.
You get good at designing algorithm because train to solve problems.
For every problem:
- Either you know the best solution: then you got your algorithm.
- Otherwise, you need to study the problem and then design an algorithm.

Design an algorithm:
- Train yourself to solve the problem by hand, create some sample inputs for further training.
- Design the algorithm from the method you have used to solve by hand.
- Code, run, debug your algorithm.
- Analyze weaknesses of your algorithm, and refine the algorithm.

Your ability to solve problems improves with experience. Every time you ask us to dothe job for you will prevent your from gaining experience.

Here we help you to fix your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900