Skip to main content
2 of 8
edited body
Nathan Merrill
  • 14.5k
  • 3
  • 53
  • 132

Matching Adjacent Words

In this challenge, you are passed two words: Your job is to determine if they are adjacent.

Two letters are adjacent if:

  1. They are the same letter, or
  2. They are lexicographically adjacent.

For example, J is adjacent to I,J, and K only. Z is not adjacent to A

Two words are adjacent if:

  1. They are the same length, and
  2. Each letter is adjacent to a unique letter in the other word.

For example, CAT is adjacent to SAD, as C>D, A>A, T>S.
FREE is not adjacent to GRRD (each E needs a letter to pair with)
.

##Input/Output

You are passed two strings, and you need to return a truthy value if they are adjacent, otherwise a falsy value. You should return within a minute for all test cases below.

You can assume that the strings will only contain alphabetic letters.

##Test Cases

Truthy:

A A A B C B DD CE DE FC ABCD BCDE AACC DBBB DJENSKE FDJCLMT DEFGHIJKL HJLEHMCHE IKLIJJLIJKKL LJLJLJLJLJHI ACEGIKMOQSUWY BLNPRDFTVHXJZ QQSQQRRQSTTUQQRRRS PQTTPPTTQTPQPPQRTP ELKNSDUUUELSKJFESD DKJELKNSUELSDUFEUS 

Falsy:

A C A Z B J JK J CC BA CE D DJENSKE GDJCLMT DEFGHIJKL HJLHMCHE IJKLIJKLKIJL LIJLLHJLJLLL AWSUKMEGICOQY RSHXBLJLNQDFZ QQSQQRRQSTTUQQQRRS PQTTPPTTQTPQPPQRTP ELKNSDUVWELSKJFESD DKJELKNSUELSDUFEUS 

This is , so the shortest answer in your favorite answer wins!

Nathan Merrill
  • 14.5k
  • 3
  • 53
  • 132