How to find the maximum rectangle within a convex GIS polygon in Javascript

Background

Recently I was exploring on a new personal project and was considering to add this functionality of finding the maximum sized rectangle within a polygon based on GIS. I tried searching for such an algorithm and found a solution from the forums and tested it — https://community.esri.com/t5/spatial-data-science-questions/how-to-find-the-maximum-rectangle-contained-within-a-polygon/td-p/408977