Here are some of the learnings I have implementing Microservice based large scale systems over years:


Problem statement

Given an index of scientists and their respective birth and death years, identify the years when maximum number of scientists were alive. These years are considered to be best years to be alive!

Solution

Use a timeline such that birth and death years are listed across the timeline. For each year, if it is a birth year, increment the count and if it is a death year, decrement the count.

Timeline for birth and death years

Source code

package main

import (
"fmt"
"sort"
)

type scientist struct {
id uint
birthYear uint
deathYear uint
}

type Node struct…


Go lang implementation for Celebrity problem is as listed below. This algorithm does not use recursion and has following complexities:

time complexity: O(n²)
space complexity: O(n)

package main

import (
"fmt"
)

func main() {
const numOfPeople = 4

matrix := [numOfPeople][numOfPeople] int {
[numOfPeople] int{0, 0, 1, 0},
[numOfPeople] int{1, 0, 1, 0},
[numOfPeople] int{0, 0, 0, 0},
[numOfPeople] int{1, 1, 1, 1},
}

indegree := []int{0, 0, 0, 0}
outdegree := []int{0, 0, 0, 0}

for i:=0; i < numOfPeople; i++ {
for j:=0; j < numOfPeople; j++ {
if matrix[i][j] == 1 {
indegree[j]++
outdegree[i]++
}
}
}

for i:=0; i<numOfPeople; i++ {
if (outdegree[i] == 0) && (indegree[i] == numOfPeople - 1) {
fmt.Println("Celebrity found: ", i)
return
}
}

fmt.Println("Celebrity not found")
}

#go-lang #algorithms


Problem statement

Let us say that there multiple jobs where each job has a deadline and an associated profit. It is also given that every job takes the single unit of time, so the minimum possible deadline for any job is 1.

Goal is to maximize total profit if only one job can be scheduled at a time.

Solution Approach

Sort the jobs first with in descending order of their respective profits; with the first job being the one with the highest profit. Pick each job from the sorted list and schedule it as late as possible. …

Ankur Gargi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store