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
javaClassAr
DecoratedFrame.java
Smallest Multiple of N with Zeros and Ones
Implementation of several common methods of LinkedList
1
qwe
Copy an array elments into another array
Palindrome String Checking
right swastik
Greedy algo Activity program