Solved

fizzArray3  challenge

Posted on 2016-08-08
1
114 Views
Last Modified: 2016-08-09
Hi,

I am working on below challenge
http://codingbat.com/prob/p142539

Psedo code description of approach :
1. find length of new array by subtracting end-start
2. create new array with above lenght
3. assign each element 0f new array using numbers between start(inclusive) and end(exclusive)

I wrote my code as below

public int[] fizzArray3(int start, int end) {
  int len=end-start;
  int[] arr=new int[len];
  for(int i=0;i<len;i++){
    arr[i]=start+i;
    
  }
  return arr;
}

Open in new window




I am passing all tests
Expected      Run            
fizzArray3(5, 10) → [5, 6, 7, 8, 9]      [5, 6, 7, 8, 9]      OK      
fizzArray3(11, 18) → [11, 12, 13, 14, 15, 16, 17]      [11, 12, 13, 14, 15, 16, 17]      OK      
fizzArray3(1, 3) → [1, 2]      [1, 2]      OK      
fizzArray3(1, 2) → [1]      [1]      OK      
fizzArray3(1, 1) → []      []      OK      
fizzArray3(1000, 1005) → [1000, 1001, 1002, 1003, 1004]      [1000, 1001, 1002, 1003, 1004]      OK      
other tests
OK

How to improve my design, approach, code? please advise
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 41749677
There is nothing wrong with your code at all, but just to give you another alternative, I might do it like this...

public int[] fizzArray3(int start, int end) {
    int[] arr = new int[end - start];
    for(int i = 0, v = start;  v < end;  i++, v++) {
        arr[i] = v;
    }
    return arr;
}

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Run AutoHotkey script directly from Notepad++ 5 220
How do I fix this situation in GIT? 2 71
Java array 10 85
Data Analysis 7 58
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question