SlideShare a Scribd company logo
1 of 2
Download to read offline
Mad Science Quarterly 
===================== 
 
The deadline for submitting papers to the Mad Science Quarterly is approaching. Professor 
Boolean's topic: On the Rate of Growth of Zombie Rabbits. In the lab, Boolean's minions 
recorded the net growth of the number of zombits for each day, which is the number of births 
minus the number of deaths (yes, zombits do die). He realized that if these figures were to be 
added up over time, it would seem like the zombits multiplied very quickly. Then everyone shall 
be convinced of his mad genius! He would proudly display these figures in his paper. Since 
some of the figures may be negative, and larger numbers are more convincing, Professor 
Boolean will choose which figures to show so that the sum is maximized. However, he must 
show a sequence of consecutive figures without omitting the unfavorable ones ­ Professor 
Boolean also needs to be scientific, you see. Unfortunately, the Mad Science Quarterly limits 
how much data can be shown ­ it is, after all, Mad. This means the mad doctor can display no 
more than a certain number of figures. 
 
Write a function answer(L, k) which returns the maximum sum Professor Boolean can obtain by 
choosing some consecutive figures from his data. L will be a list of integers representing his 
data, the daily net growth of the number of zombits over a period of time. k will be the maximum 
number of figures he can display. Each element of L will have absolute value no greater than 
100. L will contain at least 2 and no more than 7000 elements, and at least one element will be 
positive. k will be an integer, at least 3 and no greater than the length of L. 
 
Languages 
========= 
 
To provide a Python solution, edit solution.py 
To provide a Java solution, edit solution.java 
 
Test cases 
========== 
 
Inputs: 
    (int list) L = [­100, 95, 86, 47] 
    (int) k = 3 
Output: 
    (int) 228 
 
Inputs: 
    (int list) L = [40, 91, ­68, ­36, 24, ­67, ­32, ­23, ­33, ­52] 
    (int) k = 7 
Output: 
    (int) 131 
 
//Author: Neil VonHoltum 
package com.google.challenges;  
 
public class Answer {   
    public static int answer(int[] L, int k) {  
 
        int max = 0, firstklist = 0; 
 
        for(int i = 0; i < k; i++){ 
   
            firstklist += L[i]; 
        } 
 
        do{ 
   
            int currentlist = firstklist, head = 0, tail = k ­ 1; 
   
            if(currentlist > max){ 
   
                max = currentlist; 
            } 
   
            while(++tail < L.length){ 
   
                if((currentlist = currentlist ­ L[head++] + L[tail]) > max){ 
   
                    max = currentlist; 
                } 
            } 
   
            //generate next firstklist. 
            firstklist = firstklist ­ L[­­k]; 
   
        } while(k > 0); 
   
        return max; 
    }  
} 
 

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Mad Science Quarterly