Sobes.tech

Kotlin

Milliseid testjuhtumeid tuleks join meetodi jaoks kaaluda? Milliseid optimeerimisi saab lisada?

Senior
294

// broneering(istmekoht_id, kasutaja_id) PostgreSQL Begin Transaction(read_commited) seat = select * from seats where id = seat_id for update if(seat == null || seat.status == "booked") rollback return error("Koht pole saadaval") insert into bookings (user_id, seat_id, status, created_at) values (user_id, ...) update seats set status = 'booked' where id = seat_id commit return success()

Senior
220

Miks Map'is võtme on sulguv sulg ja väärtus avav sulg? Mis muutuks, kui teeksime vastupidi? Kui keeruline on containsValue võrreldes get-iga võtme järgi?

Senior
198

/* VALIK vasak.K, vasak.V1, parem.V2 VASAKULT LIITUMINE parem ON vasak.K = parem.K; */ public <K extends Comparable<K>, V1, V2> List<Triple<K, V1, V2>> join(List<Pair<K, V1>> vasak, List<Pair<K, V2>> parem) { return null; } private static class Pair<A, B> { private A esimene; private B teine; Pair(A esimene, B teine) { this.esimene = esimene; this.teine = teine; } } private static class Triple<A, B, C> { private A esimene; private B teine; private C kolmas; Triple(A esimene, B teine, C kolmas) { this.esimene = esimene; this.teine = teine; this.kolmas = kolmas; } }

Senior
161

/*Given a string, it is necessary to implement a function to check the correctness of bracket notation. Each opening bracket must correspond to a closing bracket. Opening and closing brackets must be in the correct order. Types of brackets: "{", "}", "(", ")", "[", "]". Input: "([]){}[(()())()]" Output: true Input: "[(])" Output: false Because brackets 2 and 3 are incorrectly indicated, the closing ']' appears before the closing '(' */ public boolean check(String s){ Deque<Character> stack = new ArrayDeque<>(); Map<Character, Character> map = Map.of( ')', '(', ']', '[', '}', '{' ); // ((( for( char c : s.toCharArray()){ if(map.containsValue(c)){ stack.push(c); } else if(map.containsKey(c)){ if( stack.isEmpty() || stack.pop() != map.get(c)){ return false; } } } return stack.isEmpty(); }

Senior
160