Posts

Hashtables and Hashsets

Image
Not the best solution for this problem, which also has a lot of corner cases, but the use of Hashtables and Hashsets help to achieve the goal. Whenever you have a choice, prefer Hashsets over Hashtables, and even the latter isn't super performing due to the number of casts needed. Also, in addition the slowdown here is exacerbated by the use of strings (and conversions) manipulations for the order keys. Lots of room for improvement for sure, but it is a good problem to exercise Hashtables and Hashsets in general. Code is down below, cheers, ACC. Design Order Management System - LeetCode You are asked to design a simple order management system for a trading platform. Each order is associated with an  orderId , an  orderType  ( "buy"  or  "sell" ), and a  price . An order is considered  active  unless it is canceled. Implement the  OrderManagementSystem  class: OrderManagementSystem() : Initializes the order management system. void addOrde...

1700th LeetCode Problem Solved

Image
The 1700th LC problem solved was a simple approach using frequency count and two-pointers for a linear solution in space and time. Code is down below, cheers, ACC. Mirror Frequency Distance - LeetCode You are given a string  s  consisting of lowercase English letters and digits. For each character, its  mirror character  is defined by reversing the order of its character set: For letters, the mirror of a character is the letter at the same position from the end of the alphabet. For example, the mirror of  'a'  is  'z' , and the mirror of  'b'  is  'y' , and so on. For digits, the mirror of a character is the digit at the same position from the end of the range  '0'  to  '9' . For example, the mirror of  '0'  is  '9' , and the mirror of  '1'  is  '8' , and so on. For each  unique  character  c  in the string: Let  m  be its  mirror  character. Let  f...