Panda Guru LogoPanda
Guru

Meta Phone Screen Experience: K+1th Largest Element and Valid Palindrome

Round 1

Questions:

K+1th Largest Element

Find the K+1-th largest element using a min-heap.

Edge Case: What if the array size is 2 and K = 2, making K+1 = 3?

class Solution { public int findKPlus1Largest(int[] nums, int k) { if (nums == null || nums.length == 0) { throw new IllegalArgumentException("Invalid input: nums must not be empty"); } if (k + 1 > nums.length) { throw new IllegalArgumentException("Invalid input: k + 1 must not exceed the array size"); } PriorityQueue<Integer> q = new PriorityQueue<>(); k = k + 1; // Adjust to find the K+1-th largest for (int num : nums) { q.add(num); if (q.size() > k) { q.remove(); // Remove the smallest element } } return q.remove(); // The K+1-th largest is the smallest in the heap } }
Candidate's Approach
  • Initially explained the approach and discussed complexities.
  • Implemented the solution but made a mistake in the order of operations by removing elements from the heap before adding new ones.
  • Fixed the issue by ensuring elements were added first and removed only if the heap size exceeded K+1.
  • Suggested throwing an exception for the edge case where K+1 exceeds the array size.
Interviewer's Feedback
  • The interviewer claimed there were "bugs" in the code without identifying specific issues.
  • Despite confirming correct outputs for all test cases, the interviewer insisted on skipping steps.

Round 2

Questions:

Valid Palindrome

Check if a string is a valid palindrome, ignoring digits and any non-letter characters, and considering case insensitivity.

class Solution { public boolean isPalindrome(String s) { int i = 0, j = s.length() - 1; while (i < j) { if (!Character.isLetterOrDigit(s.charAt(i))) { i++; } else if (!Character.isLetterOrDigit(s.charAt(j))) { j--; } else if (Character.toLowerCase(s.charAt(i)) != Character.toLowerCase(s.charAt(j))) { return false; // Compare valid characters only } else { i++; j--; } } return true; } }
Candidate's Approach
  • Implemented a two-pointer solution.
  • Initially converted the string to lowercase at the start but adjusted to handle characters in-place.
  • Combined checks into a single condition within the loop to reduce the number of if conditions.
Interviewer's Feedback
  • The interviewer suggested reducing the number of if conditions.
  • The candidate felt the interviewer's body language suggested dissatisfaction despite providing correct solutions.

Final Thoughts

While I arrived at correct solutions and felt confident in my explanations, the lack of clear feedback and repeated claims of "bugs" without specifics made the experience frustrating. If you’ve had similar experiences, I’d love to hear how you navigated them!


Update

I received a rejection email stating that they won’t be moving forward with my application. Disappointing, but it happens—on to the next opportunity!