Pergunta de entrevista da empresa Nextdoor

1) Compare versions given list of versions, sort them in right version order. very similar to https://leetcode.com/problems/compare-version-numbers/description/ 2) Extension of above question of given version is in form of 1.2.2-alpha, 1.2.1-beta, 1.2.11-arbitary string, sort them using following rules A) Alpha, beta, etc should comes before number version B) if both versions have string like 1-beta, 1-runs etc, sort them lexicographically order Design question asked 1) Design system for nextdoor feed? User makes post in certain neighborhood and when user in that neighborhood open app, they should see feed which contains this 2) How would you extend this some country makes some post or agency which targets number of neighborhood Technical Leadership interview 1) Deep dive into one project. Asked questions on alternative design, why certain decision is made etc type of questions Behavioral interview 1) Tell me about situation type of questions

Resposta da entrevista

Sigiloso

30 de abr. de 2025

// Comparator for part 2 static class VersionWithSuffixComparator implements Comparator { public int compare(String v1, String v2) { String[] split1 = v1.split("-", 2); String[] split2 = v2.split("-", 2); String base1 = split1[0]; String base2 = split2[0]; int baseCompare = new VersionComparator().compare(base1, base2); if (baseCompare != 0) { return baseCompare; } boolean hasSuffix1 = split1.length > 1; boolean hasSuffix2 = split2.length > 1; if (!hasSuffix1 && !hasSuffix2) return 0; if (!hasSuffix1) return 1; // v1 is numeric (stable), v2 is pre-release => v1 is greater if (!hasSuffix2) return -1; // v2 is numeric (stable), v1 is pre-release => v2 is greater // Both have suffixes: compare lexicographically return split1[1].compareTo(split2[1]); } } // Comparator for part 1 static class VersionComparator implements Comparator { public int compare(String v1, String v2) { String[] parts1 = v1.split("\\."); String[] parts2 = v2.split("\\."); int length = Math.max(parts1.length, parts2.length); for (int i = 0; i < length; i++) { int num1 = i < parts1.length ? Integer.parseInt(parts1[i]) : 0; int num2 = i < parts2.length ? Integer.parseInt(parts2[i]) : 0; if (num1 != num2) { return Integer.compare(num1, num2); } } return 0; } }