MCPcopy Create free account
hub / github.com/careercup/ctci / searchConfirm

Method searchConfirm

java/Chapter 18/Question18_5/Question.java:39–59  ·  view source on GitHub ↗
(String[] words, String word1, String word2, int distance)

Source from the content-addressed store, hash-verified

37
38 // Method to confirm other result
39 public static boolean searchConfirm(String[] words, String word1, String word2, int distance) {
40 boolean found_at_distance = false;
41 for (int i = 0; i < words.length; i++) {
42 if (words[i].equals(word1)) {
43 for (int j = 1; j < distance; j++) {
44 String loc2a = wordAtLocation(words, i - j);
45 String loc2b = wordAtLocation(words, i + j);
46 if (word2.equals(loc2a) || word2.equals(loc2b)) {
47 return false;
48 }
49 }
50
51 String loc2a = wordAtLocation(words, i - distance);
52 String loc2b = wordAtLocation(words, i + distance);
53 if (word2.equals(loc2a) || word2.equals(loc2b)) {
54 found_at_distance = true;
55 }
56 }
57 }
58 return found_at_distance;
59 }
60
61 public static void main(String[] args) {
62 String[] wordlist = AssortedMethods.getLongTextBlobAsStringList();

Callers 1

mainMethod · 0.95

Calls 1

wordAtLocationMethod · 0.95

Tested by

no test coverage detected