Sobes.tech

/* Given a string of characters. Find the number of pairs of indices i and j (i <= j) between which there are no repeating characters. For the string "aba" the answer is 5: can be ASCII [0, 0] ("a") [0, 1] ("ab") [1, 1] ("b") [1, 2] ("ba") [2, 2] ("a") */

187

Type Response interface{} Type Backend interface { Invoke(ctx context.Context, req Request) (Response, error) } var _ Backend = &BackendImpl{} // addr contains the ip:port of a specific instance func NewBackend(addr string) *BackendImpl type Balancer struct { // TODO backends []*BackendImpl index int mu sync.Mutex } var _ Backend = &Balancer{} func (b *Balancer) Invoke(ctx context.Context, req Request) (Response, error) { if len(b.backends) == 0 { return nil, fmt.Errorf("Number of backends in slice is 0") } b.mu.Lock() index := b.index if b.index + 1 == len(b.backends) { b.index = 0 index = 0 } b.mu.Unlock() resp, err := b.backends[index].Invoke(ctx, req) return resp, err } // addrs contains addresses of all load-balanced instances func NewBalancer(addrs []string) *Balancer { // TODO backends := make([]*BackendImpl, len(addrs))

187

For API Gateway, one Load Balancer, and for WebSocket, another — so two LBs in the system?

185

Have you used public clouds? If yes, which providers and services?

185

How do you work through the architecture — is there an architect in the team, platform, committee?

184

How fast will a linear search through all backends work at high RPS (for example, 30,000 RPS and 10 backends)?

183

type Balancer struct { // TODO backends []*BackendImpl index int mu sync.Mutex N int K time.Duration } var _ Backend = &Balancer{} func (b *Balancer) Invoke(ctx context.Context, req Request) (Response, error) { if len(b.backends) == 0 { return nil, fmt.Errorf("Number of backends in slice is 0") } b.mu.Lock() index := b.index for b.backends[index].banned { b.index = (b.index + 1) % len(b.backends) index = b.index } b.index = (b.index + 1) % len(b.backends) b.mu.Unlock() backend := b.backends[index] resp, err := backend.Backend.Invoke(ctx, req) if err != nil && backend.countErrors < b.N { backend.mu.Lock() backend.countErrors += 1 if backend.countErrors == b.N { backend.banned = true go func() { time.Sleep(b.K) backend.mu.Lock() defer backend.mu.Unlock() backend.banned = false backend.countErrors = 0 }() } backend.mu.Unlock() } return resp, err } // addrs contain addresses of all load-balanced instances func NewBalancer(addrs []string) *Balancer { // TODO backends := make([]*BackendImpl, len(addrs)) for _, addr := range addrs { implF := BackendImpl{ Backend: NewBackend(addr), } backends = append(backends, &implF) } return &Balancer{ backends: backends, index: 0, N: 3, // example default value K: time.Second * 10, // example default value } }

183

How to quickly check that all characters are in the window (comparing two maps)?

182

How many people were involved in the largest project you worked on? Less than ten, dozens, hundreds?

180

/** :-))) :-(( "ab :-)" = "ab " "ab :-)))" = "ab " "ab :-)))(" = "ab (" "ab ):-)" = "ab )" ":-)" = "" **/ func deleteP(str string) string { n := len(str) res := make([]byte, 0, n) i := 0 for i < n { if str[i] == ':' && str[i+1] == '-' && (str[i+2] == ')' || str[i+2] == '(') { ch := str[i+2] i += 2 for i < n && str[i] == ch { i++ } } else { res = append(res, str[i]) } } return string(res) }

180

Please tell more about your first job from 2019 to 2021.

180

How active are the job searches? Are there already offers?

180

What was the largest amount of data you worked with in databases?

180

On how many hosts did the service run and how many instances were launched?

180

Are there simpler and faster ways to load balance instead of choosing the least loaded backend?

179

Why do messages from Message Service go directly through gRPC instead of Kafka?

178

How to solve the problem of limiting parallel requests in a distributed system with multiple instances, if the user should wait rather than receive an error?

177

Find syntactic errors in the corrected code.

177

func countSubs(s string) int { result := 0 left := 0 hm := make(map[rune]int) for right := 0; right < len(s); right++ { hm[s[right]]++ for hm[s[right]] > 1 { hm[s[left]]-- if hm[s[left]] == 0 { delete(hm, s[left]) } left++ } result += (right - left + 1) } return result }

176

Implement the BulkCreateUsers method based on the proto file: create project structure, business logic, repository, and SQL queries following SOLID principles.

175
/11