Showing posts from April, 2018

Largest Triangle Area, by LeetCode

Straightforward problem by LeetCode, here it is : You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points. Example: Input: points = [[0,0],[0,1],[1,0],[0,2],[2,0]] Output: 2 Explanation: The five points are show in the figure below. The red triangle is the largest. Given the low range of the input points (max = 50), an N^3 solution should do it here. The key is to find the formula of the area of the triangle given the three coordinates, it can be found here: . Code is below, many cheers! Boris public class Solution { public double LargestTriangleArea(int[][] points) { double largest = -1; for (int i = 0; i < points.Length; i++) { for (int j = i + 1; j < points.Length; j++) { for (int z = j + 1; z < points.Length; z++) { double Ax = po

Halloween Sale, by Hackerrank

Easy problem, here: : You wish to buy video games from the famous online video game store Mist. Usually, all games are sold at the same price,   dollars. However, they are planning to have the seasonal Halloween Sale next month in which you can buy games at a cheaper price. Specifically, the first game you buy during the sale will be sold at   dollars, but every subsequent game you buy will be sold at exactly   dollars less than the cost of the previous one you bought. This will continue until the cost becomes less than or equal to   dollars, after which every game you buy will cost   dollars each. For example, if  ,   and  , then the following are the costs of the first   games you buy, in order: You have   dollars in your Mist wallet. How many games can you buy during the Halloween Sale? Notice that the problem description is the algorithm  that you want to implement, and given the small input limits, a simp