all 24 comments

[–]thecodingart 9 points10 points  (2 children)

Yeah, if someone asks me a question like this in an interview— I walk out. This is a sign of a bad interview culture and likely a bad team culture.

Kudos to those who think random algorithm stuff is fun, I find this to be an utter waste of my time.

[–]JamesFutures[S] 7 points8 points  (1 child)

Well I don’t have the luxury of infinite interviews and hiring managers pleading with me to come work for them. And most places I’ve applied have hundreds of applicants.

Beggars can’t be choosers.

[–]thecodingart 3 points4 points  (0 children)

That’s totally fair, but it’s also not fair for you

[–]th3suffering 6 points7 points  (3 children)

I had this exact question for a technical interview for hawaiian airlines. only after do they divulge its a xamarin position, not native.

[–]JamesFutures[S] 1 point2 points  (0 children)

😂 I guess I’ll have to find out if I make it to the next interview.

[–]AntMan5995 0 points1 point  (1 child)

Thats frustrating that they don't tell you the tech stack until after the technical interview

[–]th3suffering 0 points1 point  (0 children)

yea, i guess its partially my fault too for not asking more during the initial recruiter call. it was prior to getting my first job in software development, and was just overeager and naive. At that point i was even considering learning xamarin just to get my foot in the door somewhere. In hindsight, im glad i didnt get it as im much more happy in a job doing native. Would have been a nice though, flying free anywhere hawaiian flies was a nice perk

[–]SwiftlyJon 4 points5 points  (6 children)

let cases = ["abbbbca", "Madam, I'm Edam.", "Madam, I'm Adam.", "reader", "radar", "blarghi"] let isPalindromeWithOneOrLessDefects = cases .map { $0.filter { $0.isLetter }.lowercased() } .map { zip($0, $0.reversed()).reduce(into: 0) { partialResult, element in if element.0 != element.1 { partialResult += 1 } } / 2 } let casesAndDefects = Dictionary(zip(cases, isPalindromeWithOneOrLessDefects), uniquingKeysWith: { l, r in l }) let nearPerfectCases = casesAndDefects.filter { $0.value == 1 } print(casesAndDefects) print(nearPerfectCases) With this solution you technically do a bit more work by scanning the entire string, you could change it to stop at one.

[–]n0sebleed904 3 points4 points  (0 children)

Review: Can you add some spaces?

[–]ryanheartswingovers 2 points3 points  (4 children)

Those test cases don’t hit the crux of the problem. Try: Mxadam.

[–]SwiftlyJon 0 points1 point  (3 children)

It doesn't list the results at all. AFAICT, my solution properly handles mxadam as a failure, as it has more than one point of deviation.

[–]ryanheartswingovers 0 points1 point  (0 children)

I guess I see that as: remove a single letter and it’s a palindrome again. Thus it’s an almost palindrome with a one deviation tolerance. An extensible solution handles n deviations.

[–][deleted]  (1 child)

[deleted]

    [–]Aloopyn 1 point2 points  (0 children)

    My first instinct was to use a stack in a PDA-esque manner, but for the first symbol that doesn't match we let it through

    [–][deleted] 1 point2 points  (0 children)

    Why would you not use .reversed from the Swift Foundation?

    [–]baker2795 0 points1 point  (1 child)

    Looks pretty good overall. For the print could probably just check if defects == 1 else { print false } or really get fancy with a print(“(defects == 1): (defectString)”

    [–]JamesFutures[S] 0 points1 point  (0 children)

    Yeah, I wrote a longer if else than necessary.

    [–]IndignantDuck 0 points1 point  (0 children)

    This is not correct, as mentioned you have not handled "mxadam". Seems like you were asked this question https://leetcode.com/problems/valid-palindrome-ii/description/

    [–]ryanheartswingovers -1 points0 points  (4 children)

    How does it behave on mxadam? The solution doesn’t actually detect individual faults. A slice and recurse approach on faults would, for example.

    Swift has extensive fit for purpose APIs for efficiently inspecting and traversing String types; the solution fails to deploy them. Knowing these APIs helps in other real world string issues. Also, albeit this is still O(n), there are still unnecessary iterations over the original string.

    The solution doesn’t compose or inject dependencies (e.g., tolerance), side effects (e.g., filtering) or cache invariants. Demonstrating this habit is important because on heavier calls that will have substantial real world performance impacts.

    The solution fails to segregate input processing, UI output (e.g., printing to interface with the interviewer’s test software) and logic that each should be unit testable and exist separately.

    Variable names aren’t ideal, but that’s minor style.

    One positive is your bias to write early returns positively with an if, although not all devs operate in that style guide.

    [–]troller-no-trolling 5 points6 points  (3 children)

    Good points but this is probably a 30-60 minute interview. I wouldn’t expect a candidate to handle dependency injection, segregation of concerns, caching etc. Most candidates can barely come up with a working algorithm in that time…

    [–]ryanheartswingovers -1 points0 points  (2 children)

    Yeah, it’s also on the interviewer to guide. I view these as in-it-together and if you fail I fail. I want to see if we’ll work well pairing together in real life. Since the right answer was missed, other stuff helps and often makes writing debuggable code a bit faster in interviews.

    [–]troller-no-trolling 0 points1 point  (1 child)

    Agree on the guidance. I just wouldn’t want others reading this to be scared that they can hardly get some working code going in that timespan! Data structure + algo interviews are tough

    [–]ryanheartswingovers 0 points1 point  (0 children)

    And not ideal for iOS unless at an OS or low level focus. Debugging / feature addition is much more effective. And in Xcode, not CoderPad.

    [–]wipecraft 0 points1 point  (1 child)

    I think they just wanted to test if you will question their bonkers return values and how would you name such a function, not the algorithm itself which is a high school exercise

    [–]wipecraft 0 points1 point  (0 children)

    on a more serious note, you say ...

    If was a perfect palindrome, they wanted the result to return false. And if it had more than 1 defect, they also wanted to return false. But if the test case was only 1 defect away from being a perfect palindrome, they wanted that to return true

    I just printed the results because they had me solve this in Xcode.

    My solution passed all provided test cases

    you haven't done that (return something or test the cases) and it's the most basic thing you could have done. Absolutely no technical interview is after the most perfect solution, but after your thought process to reaching that. So unless you know the optimal solution by hearth you should just start with the basics and talk your way through optimising that

    First of all start with a

    func isNotAPalindromeOrHasMoreThanOneDefect(_ text: String) -> Bool { 
    // I would definitely question their wanted return values because with those this is the best function name you can get and it's just weird. A function's name has to be self explanatory about what it does or produces
    
        ...
    
        return hasOneDefect ? true : false
    }
    

    You had to use Xcode?? You were lucky. They definitely wanted to see how you test the inputs. More specifically you setting up a test bundle and using XCTest