We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Apple and Orange
Apple and Orange
Sort by
recency
|
3091 Discussions
|
Please Login in order to post a comment
func countApplesAndOranges(s: Int, t: Int, a: Int, b: Int, apples: [Int], oranges: [Int]) -> Void { let appleNewPos = apples.map { val in return val+a }.filter { val in val>=s && val<=t } let orangeNewPos = oranges.map { val in return val+b }.filter { val in val>=s && val<=t } print("(appleNewPos.count)") print("(orangeNewPos.count)") }
public static void countApplesAndOranges(int s, int t, int a, int b, List apples, List oranges) { // Write your code here long ab = apples.stream().map(n->n+a).filter(n->(n>=s && n<=t)).count(); System.out.println(ab); long bc = oranges.stream().map(n->n+b).filter(n->(n>=s && n<=t)).count(); System.out.println(bc); }
Ruby
My JS solution: