The Stable Marriage Problem (also known as Gale Shapley algorithm or Stable Matching algorithm) states that given N men and N women, where each person has ranked all members of the opposite sex in order of preference, marry the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are “stable” <Source [Wiki]>(https://en.wikipedia.org/wiki/Stable_marriage_problem).
https://www.geeksforgeeks.org/stable-marriage-problem/ https://en.wikipedia.org/wiki/Stable_marriage_problem https://www.youtube.com/watch?v=FhRf0j068ZA https://www.youtube.com/watch?v=o1olHmxDzTw
This code may not be the best possible algorithm for Stable Matching. Above links were only referenced for conceptual understanding and testing of code, any similarity in code is purely coincidential