interviewer asked me a bit about current project and then she asked me this question -
You are given an array representing the arrangement of electrons (e) and protons (p) within an atom.
Your task is to determine the number of ways to select three particles from this array to form a stable atom.
(index order should be maintained)
Definition of a Stable Atom:
For the purpose of this problem, a stable atom is defined as one in which no two consecutive particles (electrons or protons) are identical,
and the total number of particles selected is exactly three.i discussed some recursive approach first then when we were discussing the approach she told me you can achieve this without recursion and then i gave a simple approach using for loop
Follow up -
calculate all consecutive and non-consecutive ways
for this i gave O(n^3) soln then i gave O(n^2) soln, wrote the code
Follow up -
do it in O(n), then i provide a soln using hashmaps and counter with extra O(n) space.
After this we ran out of time then after wrapping up the interview she told me there is one soln in O(n) time and O(1) space, which i din't gave, So not expecting further call.
UPDATE : Got a call for next interview will update soon.
NOTE: i couldn't find this question anywhere online
