[Google SDE] Count Trapezoids

Image placeholder 9899

(This question has been seen in the interviews of the following companies: Google)

A trapezoid is a 4-sided flat shape with straight sides that has a pair of opposite sides parallel.

Question 1:
Given an integer N which represents number of edges, where bases are always 2.
Find how many trapezoid you can create with the integer N?

Use algorithmic approach to find solution, a count of possible trapezoid, don't have to use any mathematical formula (if you dont know)

E-g N =2 --> count = 1
E-g N =3 --> count = 3
E-g N =4 --> count = 6

Question 2:
Imagine now the N=4 and 2 of the edges are on the same line, how many trapezoid you can create with the integer N?

Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.