#34 Checking Strings for One Edit
Write a method that accepts two strings. It must check whether one string can be obtained from the other with one edit:
- Replacing one character in one string.
- Inserting or deleting one character in one of the strings.
public class Main {
public static void main (String[] args) {
System.out.println(editing("a", "b"); //Output: true
System.out.println(editing("ab", "b"); //Output: true
System.out.println(editing("cb", "b"); //Output: true
System.out.println(editing("ab", "ba"); //Output: false
System.out.println(editing("abbbbbbb", "bbbbbbbb"); //Output: true
System.out.println(editing("bbbbbbb", "abbbbbbb"); //Output: true
}
public static boolean editing(String first, String second) {
// write your code here
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor