# Is Rectangle? | InterviewBit | Solution Explained

I present the solutions to Is Rectangle in Python3 using multiple approaches. Problem Link.

Contents

## Logic

There’s just one key point to note: In a rectangle, of 4 sides, 2 pairs of 2 have to be equal OR all are equal. Take for example: 2, 2, 4, 4 case. Here, 2 simply represents the shorter side – and we need two of those. Similarly, 4 represents the longer side, and we need 2 of those too.

One interesting point is that all the sides can be same as well. That is, a case of 3, 3, 3, 3 is also a rectangle – since all squares are also rectangles.

## Approach 1: Sort

```class Solution:
def solve(self, A, B, C, D):
a = [A, B, C, D]
a.sort()
return int(a[0] == a[1] and a[2] == a[3])
```

## Approach 2: Frequencies

We measure the frequencies of each count. If we have a side with odd count, it means we don’t have anything to pair it up with. So, we can return False.

```from collections import Counter

class Solution:
def solve(self, A, B, C, D):
d = Counter([A, B, C, D])
for v in d.values():
if v & 1: return 0 # if some count of numbers is odd, then its an issue
return 1```

##### Tanishq Chaudhary

Producing high-quality intuitive explanations of interview problems. Currently covering LeetCode and InterviewBit.

### Recommended Posts

##### Gas Station | InterviewBit | Solution Explained

June 13, 2022

##### Majority Element | InterviewBit | Solution Explained

June 13, 2022

##### Assign Mice to Holes | InterviewBit | Solution Explained

June 13, 2022

1. Please write the proof.

2. This solution need an amendment for 2 digit number.

3. Please write a Proof for this

4. Matt Michael D’Agati is the founder of Renewables Worldwide, an Solar Firm in MA.

A few age ago, taking a leap of faith, Matt D’Agati delved into the realm of solar, and/or in a short occasion commenced effectively marketing significant amounts of power, primarily around the business industry, collaborating with solar farm developers and local businesses in the “design” of their unique plans.

Ongoing marketing within the sector, offered Matthew to participate a regional startup two years in the, and in a short time, he assumed the role of their Chief Strategy Officer, in charge of all operation and endeavor improvement, in addition to being marketed social group property.

To planned unions and shear get the job done mentality, Matthew D’Agati brought that firm from an initial initial-year revenue to in excess of a 2 hundred% surge in overall money by yr two. Based on that foundation, RW, a experienced-operated company, was produced with goal of giving you alternative electrical remedies for a more intelligent and more sustainable future.

Even more mainly, recognizing there is an untapped market in the market place and an improved approach to realize final results, RW is one of a handful of manufactures in the u.s. to place emphasis on individual acquire, concentrating in both industrial and home solar-powered town off-take. Its visualization is to make a purchases commercial infrastructure on a community-based, statewide, countrywide level, offering various sustainable fuel goods within the of RW.

This enthusiasm in the actual sustainable industry goes on to stimulate and inspire Matthew in enduring his solicit to work with institutions that have the unchanging of offering limitless fuel tips for a a whole lot more ecological destiny. Matt has already a new in companies from Hesser College.

This site uses Akismet to reduce spam. Learn how your comment data is processed.