#34 Checking Strings for One Edit

Companies:
MTS Yandex
Themes:
AlgorithmsStringsPractice

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

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in