top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Maximum Area of Triangle! InterviewBit Solution

Problem: Maximum Area of Triangle


Problem Description:

Given a character matrix of size N x M in the form of a string array A of size N where A[i] denotes ith row.

Each character in the matrix consists of any one of the following three characters {'r', 'g', 'b'} where 'r' denotes red colour similarly 'g' denotes a green colour and 'b' denotes blue colour.

You have to find the area of the largest triangle that has one side parallel to the y-axis i.e vertical and the colour of all three vertices are different.

NOTE:

  • If the area comes out to be a real number then return the ceil of that number.


Problem Constraints:

2 <= N, M <= 10^3
A[i][j] = 'r' or A[i][j] = 'g' or A[i][j] = 'b'

Input Format:

The first and only argument is a string array A of size N denoting the 2D character matrix.


Output Format:

Return a single integer denoting the area of the largest triangle that has one side parallel to the y-axis i.e vertical and the colour of all three vertices are different.


If the area comes out to be a real number then return the ceil of that number.



Example Input:

Input 1:

 A = ["rrrrr", "rrrrg", "rrrrr", "bbbbb"]

Input 2:

 A = ["rrr", "rrr", "rrr", "rrr"]