☕ Use GANs to detect Fraud?
Design Patterns in Functional Programming. Plus, a great blog post by Nvidia on using GANs to detect Financial Fraud.
Hey Guys,
Interviewing.io is a fantastic resource I wanted to share with you all.
You can book realistic mock interviews with senior FAANG engineers who will give you detailed and actionable feedback on exactly what you need to work on.
Mastering algorithms on LeetCode and system design on SystemsExpert is great, but they don’t prepare you for the pressure and stress that comes from an actual interview setting.
The best part?
You don’t pay anything until you’re hired.
Check them out here.
Special thanks to Interviewing.io for sponsoring Quastor Daily. I’m a user of the service!
Tech Snippets

Detecting Financial Fraud using GANs
 Existing approaches to identify financial fraud rely on databases of humanengineered rules that match suspicious patterns in financial transactions
 Swedbank (one of Sweden’s largest banks) has developed an approach of using GANs for anomaly detection.
 Here’s a survey paper on using GANs for anomaly detection.

Functional Programming Design Patterns with Scott Wlaschin
 Wlaschin talks about
 The core principles of functional programming design
 Functions as parameters
 Monads
 Maps
 Monoids
 Wlaschin talks about
Interview Question
Write a function to randomly generate a set of m integers from an array of size n.
Each element must have an equal probability of being chosen.
We’ll send a detailed solution tomorrow, so make sure you move our emails to primary, so you don’t miss them!
Gmail users—move us to your primary inbox
 On your phone? Hit the 3 dots at the top right corner, click "Move to" then "Primary"
 On desktop? Back out of this email then drag and drop this email into the "Primary" tab near the top left of your screen
Apple mail users—tap on our email address at the top of this email (next to "From:" on mobile) and click “Add to VIPs”
Previous Solution
As a refresher, here’s the last question
Given two straight line segments (represented as a start point and an end point), compute the point of intersection (if it exists).
Example
Input  ([(8.7, 24.8), (3.46, 23.84)], [(13.76, 29.4),(6.2, 20.5)])
Output  (3.3333, 3.3333)
Solution
This question mostly revolves around basic geometry concepts and your ability to express that in code.
Remember that a line is an infinitely long collection of points extending in two opposite directions. A line segment is just a part of that line. It has a set start point and end point.
First, we should break down the possible scenarios for our line segments.
 The line segments have the same slope
 The line segments intersect  Our two line segments are part of the same line and they’re overlapping (or they’re the same line segment).
 The line segments do not intersect
 the line segments are part of different, parallel lines
 the line segments are part of the same line but do not intersect
 The line segments have different slopes  our two line segments are part of lines that have different slopes, so those two lines have to intersect. The question is whether the point of intersection of those two lines is within our line segments.
 The line segments intersect  The point of intersection of those two lines is within our line segments.
 The line segments do not intersect  the point of intersection of those two lines is not within our line segments.
So, these are our possible cases.
Now, we have to come up with a way to represent our Line Segments.
We’ll create a class to do this for us. We can also bundle some functionality into our class so we can reuse those functions when calculating the intersection point of two line segments.
Here’s the interface for our Line Segment class.
class LineSegment
constructor(startPoint, endPoint)
calculateSlope()
calculateYIntercept()
isPointOnSegment(point)
isPointOnSegment will take in a point and return True/False depending on whether the point is on our line segment.
Now, we can implement our getLineSegmentIntersection function.
We first create objects for our Line Segments.
Then, we compare the slopes.
If the slopes are equal, then we compare the yintercepts of both line segments.
If the yintercepts are equal, that means both line segments are segments of the same line.
In that case, we return true if the lines overlap (we check this with isPointOnSegment for the start and end points of line segment 2 for line segment 1).
If the slopes aren’t equal, then we need to check if the intersection point of the two lines (the lines underlying our line segments) is within both line segments.
We first find the intersection point of the two lines using some basic algebra.
Then, we use isPointOnSegment to check if our intersection point is on line segment 1 and line segment 2.
Remember that we’re working with floating point numbers here! This is extremely important when we’re checking for equality.
We use a relative tolerance of 0.01 when checking for equality.
Here’s the Python 3 code!
Want more practice with real FAANG software engineers?
Check out Interviewing.io!
You don’t have to pay anything until you get that job at FAANG!