Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
end of bala session
/* Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window. Example: 1, 10, 3, 5, 6 .... Rextester m = new Rextester(3); //sliding window size is 3 m.next(1) = 1/1 m.next(10) = (1 + 10) / 2 m.next(3) = (1 + 10 + 3) / 3 m.next(5) = (10 + 3 + 5) / 3 m.next(6) = (3+5+6)/3 .... } */ import java.util.*; import java.lang.*; class Rextester { int s = 0; /** Initialize your data structure here. */ public Rextester(int size) { s = size+1; List<Integer> ar = new ArrayList<>(); ar.add(next()) } public double next(int val) { double outVal = 0; int sum = 0; while(ar.hasNext() && size<=s){ sum =.sum+obj.next(); } outVal = sum/s; return outVal; } //you code should pass the following tests public static void main(String args[]) { Rextester obj = new Rextester(3); System.out.println(obj.next(1)); //1 System.out.println(obj.next(5)); //3 System.out.println(obj.next(9)); //5 System.out.println(obj.next(4)); //6 } }
run
|
edit
|
history
|
help
0
Find Median in Large File of Integers
bubble sort
asdasd
Coding Challenge - 04 (Perfect numbers)
java palindrome check
3.F
DFS in Graph
메소드구현하기
Problem: on_off
Circular array Loop?