leochen40505
BAN USER
special case: lines of rectangles may not always be horizontal or vertical. e.g. (0, 0), (1, 2), (-3, 4), (-4, 2)
assumption: set of points are store in a hashed table. let's call it pointsSet
solution steps:
1. select any point
2. iterate through the rest of the points. O(n)
3. for each points in step 2, calculate the slope of the 2 points from step 1 and 2. using the slope(double, x/y) as key, store the point from step 2 into a hash table(let's call it slopeSet) and check if there's a tangent slope exists from previous points(by checking positive and negative of the inverse slope. if slope is represented as x/y, then check for -y/x and y/x)
4. if a previous slope is found in the slopeSet. use the 3 points to check if the fourth point exists in pointsSet(by calculating x and y displacements of the 3 points to get the fourth point). if it does compare the area with the current smallest area store in a variable(initialized as -1. if the value is -1 then replace the value with current area. else compare the area)
5. remove the point selected in step 1. and start from step 1 again until all points are compared. return smallest area. if -1 is returned then it means there's no rectangle formed from the points. O(n)
Performance evaluation:
O(n^2) since there are 2 for loops with O(n)
c++ solution
use an array as index of a multi-base on different digit number
vector<int> dimension = getDim();
//subtract 1 from every dimension to use as index
for (int idx = 0; idx < dimension.size(); idx++) {
dimension[idx]--;
}
//use as the array of index pass to getElement
vector<int> idxV = dimension;
long retSum = 0;
while(true) {
int idx = 0;
//update index array
while(true) {
//all iteration are done. return sum
if (idx >= dimension.size())
return retSum;
if (idxV[idx] == 0) {
idxV[idx] = dimension[idx];
idx++;
} else {
idxV[idx]--;
break;
}
}
retSum += getElement(idxV);
}
RepConnieLavender, Animator at Altera
My name is ConnieLavender . I am working as a Broker associate . I love field work and visiting different places to ...
RepVictoriaMitchell, Animator at ABC TECH SUPPORT
I am an Analysis Manager.I have 7 years of experience in leveraging data analysis to develop. And I love ...
RepShayneRies, Android Engineer at ASAPInfosystemsPvtLtd
I am Shayne , working as a Playwright at Woilds , where I write scripts for theatrical productions. Works with more experienced ...
Repjennykyiler, Area Sales Manager at AMD
Jenny , an Assistant Secretary with a track record of employer satisfaction in performing various administrative tasks, and completing visual presentations ...
RepDavidJohaan, Digital marketing Experinced at Abs india pvt. ltd.
I am David , a scanner operator for seven years in the industry Paearb. Six months ago , I’d an injury ...
Repdalecronin028, Animator at Pinterest
Hello, I am Dale. I am a Tourist guide who welcomes tourists . Tourist Guides act as ambassadors of the country ...
RepYuvaanSmith, Analyst at ADP
Monitor and coordinate project information as it relates to the finances of the organization both before, during, and after bringing ...
RepLoriEver, Applications Developer at ASAPInfosystemsPvtLtd
LoriEver a Rancher working at William Wanamaker & Sons. It's been almost 6-10 years that he has been working this ...
RepCandiRoy, HR at ASU
I am a qualified CEO with experience in overseeing the daily activities of small businesses and large corporations alike. I ...
Repchrishwalsh369@gmail.com, Android Engineer at ABC TECH SUPPORT
A computer operator is a role in IT that oversees the running of a computer system.Apart from this, today ...
RepEileenBaker, Applications Developer at ABC TECH SUPPORT
I am an experienced and dedicated professional with a track record of effective mentorship. Nowaday most people search for Ambani ...
RepMinnieRuffin, Accountant at Boomerang Commerce
Minnie , a business leader professional accustomed to managing projects with Vashikaran Specialist in nagpur pay after results with fast-paced and ...
RepJessicaHanda, Front-end Software Engineer at ABC TECH SUPPORT
Jessica , hard-working Packer with a strong determination to finish all assignments in a timely manner. I have joined a few ...
RepNiaNorna, Analyst at ADP
I am an established career journalist with 15 years of writing and copy editing experience in the newsroom. Seeking to ...
RepCecilPonton, Java Developer at Boeing
Cecil , an enthusiastic professional Photographer with 2 years of experience with a true passion for capturing life’s moments through ...
Replimachiya788, Associate at ABC TECH SUPPORT
LeviWebber , is a Housekeeping cleaner at Exact Solutions . I am also exploring new things . Mayong Assam tantrik contact number . Housekeepers ...
RepYaniraBryant, Accountant at CGI-AMS
I am Yanira , a writer by fate. Went from writing for media outlets to exploring the world of content creation ...
RepKeciaFowler, Area Sales Manager at Auto NInja
My name is Kecia and I am a results-oriented Real Estate Appraiser Trainee with a strong determination to perform great ...
RepHenryLee, Accountant at AMD
I am a creative and 5 years experienced beautician. I have experience with most cosmetology tools, including razors, nail clippers ...
RepJamieWilliams, Android Engineer at Email Customer Service
My name is Jamie.and i am a Translator It's been almost 2 years since I worked in this ...
Repdennisrichar76, Accountant
I am a resourceful and seasoned Mechanical drafter with a strong customer service and industries. I have a strong knowledge ...
Reppamelajones9873, Area Sales Manager at Facebook
Hello I am Pamela Jones. I am an Animal Control Worker Here, Animal control officers are generally employed by a ...
Repcolleenpbeverly02, Android test engineer at ABC TECH SUPPORT
Hello I am Colleen Dedicated and hardworking Geographic information specialist analyst with 15 years of experience working with ArcGIS software ...
Repsushiswla65, Area Sales Manager at ABC TECH SUPPORT
My name is SarahProctor . I am working as a Video editor at Konsili . I am exploring some magical tricks . vashikaran ...
RepElizabethMaxim, Android test engineer at AMD
A financial economist is responsible for the production and distribution of goods and services. We are also responsible for collecting ...
Repdebrak836636, Developer Program Engineer at Arista Networks
I am Debra , a multilingual (English/Italian/French) Judge with 5 years of experience in presiding over court proceedings, prosecuting ...
Repchomeshgeles, Android Engineer at ABC TECH SUPPORT
ReevesMildr , a builder working at Independent Investors . It has been almost 5 years since I have been working here. I ...
Repracheljennir, Personnel consultant at Infinite Wealth
Rachel, I am a Personnel consultant who acts as mediator between employers and job seekers. The main task of I ...
RepMargySpencer, Area Sales Manager at ABC TECH SUPPORT
Hey my name is Margy and i am a scientific photographer. I have full experience of 5 years of work ...
- leochen40505 May 27, 2019