Last active
March 9, 2024 15:06
-
-
Save eltonjncorreia/f4b0e04367b36fc51985e189bfec561e to your computer and use it in GitHub Desktop.
s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Você está escrevendo uma parte do nosso sistema anti-fraude de pagamentos. | |
// Uma das formas de detectarmos fraudes é quando o mesmo cliente faz mais de um pagamento numa janela muito curta de tempo. | |
// Seu programa receberá os clientes que estão efetuando pagamentos através de um stream, e deve identificar clientes repetidos que apareçam próximos. | |
// Escreva um algoritmo que leia um stream de clientes, onde cada cliente é identificado por um número inteiro, e escreva na saída cada vez que um cliente aparecer repetido numa janela de tamanho J. | |
package main | |
import "fmt" | |
func main() { | |
var window = 4 | |
Stream := []int{7, 10, 5, 10, 8, 3, 1, 4, 3, 3, 5, 1} | |
counts := make(map[int]int) | |
for _, stream := range Stream { | |
ReadStream(stream, window, counts) | |
} | |
} | |
func ReadStream(value, window int, counts map[int]int) { | |
counts[value]++ | |
if counts[value] > 1 { | |
fmt.Println(value) | |
} | |
if len(counts) >= window { | |
delete(counts, counts[0]) | |
} | |
if len(queue) > window { | |
oldValue := queue[0] | |
queue = queue[1:] | |
seen[oldValue]-- | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment