Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8118677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:33:55+00:00 2026-06-06T04:33:55+00:00

Circle Summation: There are N children sitting along a circle, numbered 1,2,…,N clockwise. The

  • 0

Circle Summation:

There are N children sitting along a circle, numbered 1,2,…,N clockwise. The ith child has a piece of paper with number ai written on it. They play the following game:

In the first round, the child numbered x adds to his number the sum of the numbers of his neighbors.
In the second round, the child next in clockwise order adds to his number the sum of the numbers of his neighbors, and so on.
The game ends after M rounds have been played.

Input:

The first line contains T, the number of test cases. T cases follow. The first line for a test case contains two space seperated integers N and M. The next line contains N integers, the ith number being ai.

Output:

For each test case, output N lines each having N integers. The jth integer on the ith line contains the number that the jth child ends up with if the game starts with child i playing the first round. Output a blank line after each test case except the last one. Since the numbers can be really huge, output them modulo 1000000007.

Constraints:

1 <= T <= 15

3 <= N <= 50

1 <= M <= 10^9

1 <= ai <= 10^9

Sample Input:

2

5 1

10 20 30 40 50

3 4

1 2 1

Sample Output:

80 20 30 40 50

10 60 30 40 50

10 20 90 40 50

10 20 30 120 50

10 20 30 40 100

23 7 12

11 21 6

7 13 24

This is a problem in INterviewStreet. I wrote a logic and worked successfully when keeping that entire logic in One method.
But when i try to do it by using Two methods, Array ‘b’ in “main” method getting over written by Array ‘a’ in “mtd” method.
I tried my best and couldn’t find the what causing it.

import java.util.Scanner;
public class Solution{ 
    public static void main(String[] args) {
    Solution obj = new Solution();
        Scanner sc = new Scanner(System.in);
        int n,k; // Variables
    long m;
    int t = sc.nextInt();
           for(int rot=0;rot<t;rot++) {
            n = sc.nextInt(); // reading input
            m = sc.nextLong(); // reading input
            long[] b = new long[n]; 
            for(int i =0; i< n; i++)
               b[i] = sc.nextLong(); // Reading values into array
                for(int i=0; i< n;i++ ){  // Loop
                obj.mtd(b,i,n,m); // calling Method "mtd"
            System.out.println();
            }
            System.out.println();
        }
    }
         void mtd(long[] a, int j,int n, long m) // "mtd" method
    {

            int p=0;        
                for(; p< m && j<n; j++,p++){     // logic
                    if(j==0){
                        a[0]= a[0]+a[1]+a[n-1];
                    }else if(j==n-1){
                        a[n-1]= a[0]+a[n-2]+a[n-1];
                    }else{
                        a[j]= a[j-1]+a[j]+a[j+1];
                    }
               }
                do{
                    if(j == n){                 // 
                    for(j=0; p< m && j< n; j++,p++){
                         if(j==0){
                                a[0]= a[0]+a[1]+a[n-1];
                        }else if(j==n-1){
                                a[n-1]= a[0]+a[n-2]+a[n-1];
                        }else{
                                a[j]= a[j-1]+a[j]+a[j+1];
                        }
                   }
            }
            }while(p!=m);
                long z;
             for(int k =0; k< n; k++){
                z=a[k]%1000000007;
                 System.out.print(z+" ");    // printing array after all operations
             }
    }
}

The Output i am getting is :

80 20 30 40 50

80 130 30 40 50

80 130 200 40 50

80 130 200 290 50

80 130 200 290 420

23 7 12

142 261 77

883 1624 2987

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:33:57+00:00Added an answer on June 6, 2026 at 4:33 am

    Java is pass by value, but when you pass an Object, the value of the reference to the object is passed on. Using this reference if you make any changes to the contents of the Object, the changes are reflected back.

    And Arrays are treated as Objects in Java.

    If you intend to pass a copy of your Array and work with it, first create a copy using System.arraycopy() method, and then pass the copy of the Array. Here’s an example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a round circle in the center of my app. With a 480x800
I have problem with circle-rectangle intersection.Though A number of discussion i found about it
Suppose we have a numbered circle. We want to go from point A to
There is a circle I want to rotate. If it is not scaled its
trying to draw circle divided to dynamically provided number of sectors. In the end
There is a circle on SharePoint2010 page http://sharepoint2010.microsoft.com/Pages/default.aspx which is made by Silverlight. I
Possible Duplicate: Draw Circle using css alone I would like to know if there
Hey I have circle as below. Circle has two points A(latitude1,longitude1) and B(latitude2, longitude2).
Circle Rotation onTouch Only works when clicked once after that it does not do
I need a circle object as follows : The name and count extracts info

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.