SHARE
TWEET

Untitled

a guest Aug 25th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "sort"
  6. )
  7.  
  8. func main(){
  9.  
  10.     K := 3
  11.     A := []int{2,1,3,1,2,2,3}
  12.  
  13.  
  14.     counter     := make(map[int] int)
  15.     suitable    := make(map[int] bool)
  16.    
  17.     for _,val := range A {
  18.         _, exist := counter[val]
  19.         if !exist {
  20.             counter[val] = 1
  21.         } else {
  22.             counter[val] ++
  23.         }
  24.     }
  25.  
  26.     for i := 0 ; i <= (len(A) - K) ; i++ {
  27.         subCounter      := CopyMap(counter)
  28.         suitableValue   := 0
  29.         ref             := 0
  30.        
  31.         for j := i ; j < (i + K) ; j++ {
  32.             subCounter[A[j]] --
  33.             subCounter[A[j] + 1] ++
  34.         }
  35.        
  36.         for kk, vv := range subCounter {
  37.             if vv > ref {
  38.                 ref             = vv
  39.                 suitableValue   = kk
  40.             }    
  41.         }
  42.        
  43.         suitable[suitableValue] = true
  44.     }    
  45.  
  46.     output := []int{}
  47.  
  48.     for k,_ := range suitable {
  49.         output = append(output, k)
  50.     }
  51.  
  52.     sort.Ints(output)
  53.  
  54.     fmt.Println(output)
  55. }
  56.  
  57.  
  58. func CopyMap(m map[int]int) map[int]int {
  59.     outMap := make(map[int]int)
  60.    
  61.     for k,v := range m {
  62.         outMap[k] = v
  63.     }
  64.    
  65.     return outMap
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top