Related
For example if input is:
2 0 6 3 1 6 3 1 6 3 1
then output should be 6 3 1.Need to find the first repetition cycle.
class FindDuplicate
{
void printRepeating(int arr[], int size)
{
int i;
System.out.println("The repeating elements are : ");
for (i = 0; i < size; i++)
{
if (arr[Math.abs(arr[i])] >= 0)
arr[Math.abs(arr[i])] = -arr[Math.abs(arr[i])];
else
System.out.print(Math.abs(arr[i]) + " ");
}
}
public static void main(String[] args)
{
FindDuplicate duplicate = new FindDuplicate();
int arr[] = {1, 2, 3, 1, 2, 3, 1, 2, 3 };
int arr_size = arr.length;
duplicate.printRepeating(arr, arr_size);
}
}
https://pastebin.com/12bnjzfw
Have used java 8 streams for collection creation.
for (int seqSize = ints.size() / 2; seqSize > 0; seqSize--) { //It should be first cycle. Main priority is biggest sequence
for (int i = 0; i < ints.size() / seqSize; i++) { //Start position of the first block
for (int j = i + seqSize; j < ints.size() - seqSize + 1; j++) {
if (ints.subList(i, i + seqSize).equals(ints.subList(j, j + seqSize))) {
System.out.println("Answer is: " + ints.subList(i, i + seqSize));
return;
}
}
}
}
class FindDuplicate {
static int STRING_LENGTH = 3;
void printRepeating(int arr[], int size) {
int i;
System.out.println("The repeating elements are : ");
String strVal = "";
for (int ii = 0; ii < size; ii++) {
strVal += arr[ii];
}
// strVal now has something we can search with.
for (i = 0; i < size; i++) {
int end = Math.min(size,i+STRING_LENGTH );
String searchString = strVal.substring(i, end);
if (searchString.length() != STRING_LENGTH)
break; // at end of arr, doesn't have length to search
int matchIndex = strVal.indexOf(searchString, i+1);
if (matchIndex != -1) {
String match = strVal.substring(matchIndex, matchIndex + STRING_LENGTH);
System.out.print(match + " ");
break; // done with loop
}
}
}
public static void main(String[] args) {
FindDuplicate duplicate = new FindDuplicate();
int arr[] = {1, 2, 3, 1, 2, 3, 1, 2, 3 };
int arr_size = arr.length;
duplicate.printRepeating(arr, arr_size);
}
}
Loop through those array elements and cache your elements until you have the same value for example
List list = Arrays.asList(1,2,3);
if(list.contains(element))
//code to check here
you will need get size of your list and based on that check exactly this amount of items if they match if yes then output if not clear cache and start cache from the begging.
Using java, I am supposed to create a program that stores the square of the numbers 0, 1, 2 & 9 in an ArrayList of 10 elements.
I have created part of the code that displays the numbers and its squares but the program goes straight down with all the numbers and does not look organized. Can someone help me write it out like like this instead:
number: 0 square: 0
number: 1 square: 1
number: 2 square: 4
Code
public static void main(String[] args) {
int[] temp = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (int value : temp) {
System.out.println(value);
}
for (int i = 0; i < temp.length; i++) {
temp[i] = (int) Math.pow(temp[i], 2);
}
for (int value : temp) {
System.out.println(value);
}
}
You need just one loop like this :
public static void main(String[] args) {
int[] temp = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (int i = 0; i < temp.length; i++) {
System.out.println(temp[i] + "\t" + (int)Math.pow(temp[i], 2));
}
}
OutPut
0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
If you want to store your results in an ArrayList you can use :
List<int[]> array = new ArrayList<>();//create a List which take an array of int
int arr[] = new int[2];//create a temporary array of 2 elements
for (int i = 0; i < temp.length; i++) {
System.out.println("Number: " + temp[i] + " \tSquare: " + (int) Math.pow(temp[i], 2));
arr[0] = temp[i];//add your number to your array pos 1
arr[1] = (int) Math.pow(temp[i], 2);//add the power to the 2ed position
array.add(arr);//add your array to your list
}
public static void main(String[] args) {
int[] temp = {0, 1,2,3,4,5,6,7,8,9};
// here you are printing all your numbers in the array, so the output will be:
// 0
// 1
// ...
// 9
for (int value : temp) {
System.out.println(value);
}
// after that, you calculate and store them in the same array; so your array now look like this:
// [0,1,4,9,...,81]
for (int i = 0; i < temp.length; i++) {
temp[i] = (int) Math.pow(temp[i], 2);
}
// here you are printing again your array
// 0
// 1
// 4
// ...
// 81
for (int value : temp) {
System.out.println(value);
}
}
to get your desired outcome, you have to calculate the number before printing everything... one option will be to create another array
int[] square = new int[9];
calculate in the first for loop and save the result in the square array and print them, something like this:
for (int i = 0; i < temp.length; i++) {
square[i] = (int) Math.pow(temp[i],2);
System.out.println("number " + temp[i] + " square: " + square[i]);
}
Assuming the original question which referred to an ArrayList was correct (the OP's example only had an array), and assuming the results are supposed to be stored in the array (per the question), then the following will work:
public static void main(String[] args)
{
// instantiate ArrayList
List<Double> array = new ArrayList<>();
// load the values
for (int i = 0; i < 10; ++i) {
array.add(i, Math.pow(i, 2));
}
// output
for (int i = 0; i < array.size(); ++i) {
System.out.println(String.format("%2d\t%3.0f", i, array.get(i)));
}
}
Output:
0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
Try this :
public static void main(String[] args) {
int[] temp = {0, 1,2,3,4,5,6,7,8,9};
for (int value : temp) {
System.out.println("number : "value);
}
for (int i = 0; i < temp.length; i++) {
temp[i] = (int) Math.pow(temp[i], 2);
}
for (int value : temp) {
System.out.println(" square : " + value + "\n");
}
}
As a part of the Java interview question paper I have got following issue to solve.
But I am bit wonder whether how can I implement it without any Collection or intermediate Array.
Question:- Count duplicates from int array without using any Collection or another intermediate Array
Input values:- {7,2,6,1,4,7,4,5,4,7,7,3, 1}
Output:- Number of duplicates values: 3
Duplicates values: 7, 4, 1
I have implemented following solution but was not completed one.
Any one has some idea? Thanks.
public static void duplicate(int numbers[]) {
for (int i = 0; i < numbers.length; i++) {
boolean duplicate = false;
int j = 0;
while (j < i){
if ((i != j) && numbers[i] == numbers[j]) {
duplicate = true;
}
j++;
}
if (duplicate) {
System.out.print(numbers[i] + " ");
}
}
}
The easiest way to solve this problem is to sort the array first, and then just walk through the array counting duplicates as you encounter them:
int[] numbers = new int[]{7,2,6,1,4,7,4,5,4,7,7,3,1};
int temp = 0;
// I chose to do a bubble sort of the array,
// but you are free to use any method you wish (e.g. Arrays.sort)
System.out.print("Duplicates values: ");
for (int i=0; i < numbers.length; ++i) {
for (int j=1; j < (numbers.length - i); ++j) {
if (numbers[j-1] > numbers[j]) {
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
}
}
// walk through the sorted array and count duplicates
int numDup = 0, dupCount = 0;
int previous = -1;
for (int i=0; i < numbers.length; ++i) {
if (numbers[i] == previous) {
++numDup;
if (numDup == 1) {
++dupCount;
if (dupCount == 1) {
System.out.print(numbers[i]);
}
else {
System.out.print(", " + numbers[i]);
}
}
}
else {
previous = numbers[i];
numDup = 0;
}
}
System.out.println("\nNumber of duplicates values: " + dupCount);
Output:
Duplicates values: 1, 4, 7
Number of duplicates values: 3
Note that my output order is reverse of what you have, because you need to read through the entire array before you know how many total duplicates you have. Also, I will point out that the only state this solution uses is the input array itself, plus a couple of int varibles here and there.
This code has been tested in IntelliJ and it works correctly.
Agreed to Tim #tim-biegeleisen. Just minor change. Use the Arrays to sort the array.
import java.util.*;
public class DuplicateClass {
public static void main(String[] args) {
int[] values = { 7, 2, 6, 1, 4, 7, 4, 5, 4, 7, 7, 3, 1 };
duplicate(values);
}
public static void duplicate(int numbers[]) {
Arrays.sort(numbers);
int previous = numbers[0] - 1;
int dupCount = 0;
for (int i = 0; i < numbers.length; ++i) {
if (numbers[i] == previous) {
++dupCount;
} else {
previous = numbers[i];
}
}
System.out.println("There were " + dupCount + " duplicates in the array.");
}
}
These are all great answers. One other is to use an int/double and set it's bits when you encounter a number. This works if the array's values are less than 32/64 depending on the type you use.
Below is an example of how you would do that with an integer.
public class SetThoseBits{
// 0000 0000 0000 0000 000 0000 0000 0000
public static int data = 0;
public static void main(String [] args){
// Gurantee that the numbers are less than 32
int[] values = { 7, 2, 6, 1, 4, 7, 4, 5, 4, 7, 7, 3, 1 };
duplicates(values);
}
public static void duplicates(int [] values){
for(int i : values){
if(testBit(i)){
System.out.println("Duplicate :" + i);
} else{
setBit(i);
}
//printBits();
}
System.out.println("Finished!");
}
// Sets the bit at a specific position
public static void setBit(int index){
data = data | (1 << index);
}
// This function will test the bit at the index of the given integer
// If it's set, it returns true
public static boolean testBit(int index){
return ((data & (1 << index)) != 0);
}
public static void printBits(){
for (int x = 31; x >= 0; x--){
if(testBit(x)){
System.out.print("1");
} else{
System.out.print("0");
}
}
System.out.println("0");
}
}
I believe the the other answers are better given your question..but demonstrating this as an alternative shows that you're thinking about it dynamically. If the requirements of the question changed a little this answer might be more appropriate.
Further if you only need to keep track of duplicates given the smallest footprint possible, you could do something similar to what is above or use java's BitSet class to make your life easier.
http://docs.oracle.com/javase/7/docs/api/java/util/BitSet.html
Edit: It is also possible to have values higher than 64 given that you create a function that holds an array of bytes like the BitSet class. For this exact question this isn't helpful given the constraint to not use an array or collection.
private static int solution3(List<Integer> inputArr) {
// Time Complexity O(N)
// Space Complexity O(1)
// Stream
return (int) inputArr.stream()
.collect(Collectors
.toMap(Function.identity(), v -> 1, Integer::sum))
.entrySet().stream()
.filter(k -> k.getValue() >= 2)
.count();
}
Keeping one extra variable for maintaining count, plus sorting of array in the initial phase.
public static void main(String[] args) {
int[] numbers = { 7, 2, 6, 1, 4, 7, 4, 5, 4, 7, 7, 3, 1 };
Arrays.sort(numbers);
System.out.println("Sorted Array is :: = " + Arrays.toString(numbers));
int count = 0;
int tempCount = 0; // to keep local count of matched numbers
String duplicates = "";
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] == numbers[i - 1]) {
if ((tempCount == 0)) { // If same number is repeated more than
// two times, like 444, 7777
count = count + 1;
tempCount = tempCount + 1;
duplicates = duplicates.concat(Integer.toString(numbers[i])
+ ",");
}
} else {
tempCount = 0;
}
}
System.out.println("No of duplicates :: = " + count);
System.out.println("Duplicate Numbers are :: = " + duplicates);
}
output
Sorted Array is :: = [1, 1, 2, 3, 4, 4, 4, 5, 6, 7, 7, 7, 7]
No of duplicates :: = 3
Duplicate Numbers are :: = 1,4,7,
int numbers[]={7,2,6,1,4,7,4,5,4,7,7,3, 1};
String temp="";
int count=0;
Arrays.sort(numbers);
for (int i = 0; i < numbers.length; i++) {
boolean duplicate = false;
for(int j = 0; j < numbers.length; j++) {
if ((i != j) && numbers[i] == numbers[j]) {
duplicate = true;
}
}
if (duplicate) {
if(!temp.contains(""+numbers[i]))
{
temp+=numbers[i]+", ";//adding a number if its duplicate
count++;//counting unique duplicate number
}
System.out.print(numbers[i] + " ");
}
}
System.out.println("\nDuplicates are: "+temp+" count: "+count);
Output:
Duplicates are: 1, 4, 7, count: 3
I think, this is also a way to calculate it:
public class App {
public static void main(String[] args) {
Integer[] intArr = { 7, 2, 6, 1, 4, 7, 4 };
List<Integer> listInt = Arrays.asList(intArr);
Map<Integer, Integer> map = new HashMap<>();
Integer dupCount = 0;
StringBuilder dupvalues = new StringBuilder();
for (Integer integer : intArr) {
int times = Collections.frequency(listInt, integer);
if (map.containsKey(integer)) {
dupvalues.append(integer).append(",");
dupCount++;
} else
map.put(integer, times);
}
System.out.println("There were " + dupCount + " duplicates in the array. The value are : "+dupvalues);
}
}
This is the simplest solution I can think of. I just added an extra counter so that integers with two or more repetitions still in the array are ignored.
static int findNumber(int[] arr)
{
int duplicateCounter = 0;
System.out.print("Duplicates: ");
for(int i = 0; i < arr.length; i++)
{
boolean duplicate = false;
int numOfOccurrences = 1;
for (int j = (i+1); j < arr.length; j++)
{
if (arr[i] == arr[j])
{
numOfOccurrences++;
duplicate = true;
}
}
if(numOfOccurrences == 2 && duplicate == true)
{
duplicateCounter++;
System.out.print(arr[i] + " ");
}
}
return duplicateCounter;
}
My test run: Test run
Input: 1, 2, 3, 4, 2, 4, 1, 1, 1
Duplicates: 2 4 1
Number of duplicates: 3
Below method not use any collection, just use Arrays.sort() method to help sort array into ascending order as default, e.g array = [9,3,9,3,9] will sort into [3,3,9,9,9].If input [9,9,9,9,9], expected result is 1, since only repeated number is 9.If input [9,3,9,3,9,255,255,1], expected result is 3, since repeated numbers are 3,9,255. If input [7,2,6,1,4,7,4,5,4,7,7,3,1], expected result is 3, since repeated numbers are 1,4,7.
public static int findDuplicateCountsInArray(int[] nums) {
// Sort the input array into default ascending order
Arrays.sort(nums);
int prev = nums[0];
int count = 0;
// Recording a number already a repeated one
// e.g [9,9,9] the 3rd 9 will not increase duplicate count again
boolean numAlreadyRepeated = false;
for(int i = 1; i < nums.length; i++) {
if(prev == nums[i] && !numAlreadyRepeated) {
count++;
numAlreadyRepeated = true;
} else if(prev != nums[i]) {
prev = nums[i];
numAlreadyRepeated = false;
}
}
return count;
}
Here I have written code in JAVA. also the inputted numbers, have been considered as String. This question has also been added to CODEWARS. and I hope this simple solution helps You
public class countingduplicates {
public static void main(String[] args) {
int i=0,j=0,c=0,a=0;
String text="7261474547731";
text=text.toLowerCase();
for(i=0; i<text.length(); i++) {
for(j=0; j<text.length(); j++) {
if(text.charAt(i) == text.charAt(j)) {
c++;
}
}
System.out.println(text.charAt(i) + " occured " + c + " times");
if(c>1) {
a++;
}
String d = String.valueOf(text.charAt(i)).trim();
text = text.replaceAll(d,"");
c = 0;
i = 0; //cause i have trimmed the string and by default i increases by 1, so i have to assign it =0
j = 0; //cause i have trimmed the string and by default j increases by 1, so i have to assign it =0
}
System.out.println("Total count of Duplicates:" + a);
}
}
This is practically very easy in Python. You can check this code. I am giving you 2 methods. Please take a look at it.
array = ['a','b','c','d','a','b','c','d','e']
array1 = [1,2,2,3,3,3,4,5,6,4,4,5,5,5,5]
output = {i : array1.count(i) for i in array1 }
print(output) #{1: 1, 2: 2, 3: 3, 4: 3, 5: 5, 6: 1}
output2 = dict(Counter(array1))
print(output2) #{1: 1, 2: 2, 3: 3, 4: 3, 5: 5, 6: 1}
If you want only the Duplicate numbers, then :
#method 1
output = [k for k,v in Counter(array1).items() if v>1 ]
print(output)
If you want only the Distinct numbers, then :
#method 1
#Prints only Distinct absolute values
O2 = set([abs(i) for i in array1])
print(O2) #1,2,3,4,5,6
Have a program where the user inputs 10 int values into the array. Lastly I need to pull out the distinct values and display them. Added my second for loop which would determine if the the value is distinct (i.e. meaning if the number appears multiple times it is only displayed once).
For instance, let say I pass in the numbers: 1, 2, 3, 2, 1, 6, 3, 4, 5, 2 the distinct array should only contain numbers {1, 2, 3, 6, 4, 5}
import java.util.Scanner;
import java.io.*;
public class ArrayDistinct {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
// Create arrays & variables
int arrayLength = 10;
int[] numbers = new int[arrayLength];
int[] distinctArray = new int[arrayLength];
int count = 0;
System.out.println("Program starting...");
System.out.print("Please enter in " + numbers.length + " numbers: ");
for (int i = 0; i < numbers.length; i++) {
numbers[i] = input.nextInt();
}
for (int i = 0; i < numbers.length; i++) {
int temp = numbers[i];
int tempTwo = numbers[i + 1];
if (tempTwo == temp) {
count++;
distinctArray[i] = temp;
}
}
// Print out results
} // end main
} // end class
Try this :
Set<Integer> uniqueNumbers = new HashSet<Integer>(Arrays.asList(numbers));
uniqueNumbers will contain only unique values
In Java 8
Stream< T > distinct()
Returns a stream consisting of the distinct elements (according to
Object.equals(Object)) of this stream. For ordered streams, the
selection of distinct elements is stable (for duplicated elements, the
element appearing first in the encounter order is preserved.) For
unordered streams, no stability guarantees are made.
Code:
Integer[] array = new Integer[]{5, 10, 20, 58, 10};
Stream.of(array)
.distinct()
.forEach(i -> System.out.print(" " + i));
Output:
5,10,20,58
Read More About distinct function
Try this code.. it will work
package Exercises;
import java.util.Scanner;
public class E5Second
{
public static void main(String[] args)
{
Scanner In = new Scanner(System.in);
int [] number = new int [10];
fillArr(number);
boolean [] distinct = new boolean [10];
int count = 0;
for (int i = 0; i < number.length; i++)
{
if (isThere(number,i) == false)
{
distinct[i] = true;
count++;
}
}
System.out.println("\nThe number of distinct numbers is " + count);
System.out.print("The distinct numbers are: ");
displayDistinct(number, distinct);
}
public static void fillArr(int [] number)
{
Scanner In = new Scanner(System.in);
System.out.print("Enter ten integers ");
for (int i = 0; i < number.length; i++)
number[i] = In.nextInt();
}
public static boolean isThere(int [] number, int i)
{
for (int j = 0; j < i; j++)
if(number[i] == number[j])
return true;
return false;
}
public static void displayDistinct(int [] number, boolean [] distinct)
{
for (int i = 0; i < distinct.length; i++)
if (distinct[i])
System.out.print(number[i] + " ");
}
}
One possible logic: If you're supposed to only sort out "unique" numbers, then you'll want to test each number as it's entered and added to the first array, and loop through the array and see if it's equal to any of the numbers already there; if not, add it to the "unique" array.
Sets in java doesn't allow duplicates:
Integer[] array = new Integer[]{5, 10, 20, 58, 10};
HashSet<Integer> uniques = new HashSet<>(Arrays.asList(array));
That's it.
Something like this should work for you:
Scanner input = new Scanner(System.in);
// Create arrays & variables
int arrayLength = 10;
int[] numbers = new int[arrayLength];
int[] distinctArray = new int[arrayLength];
int count = 0;
Set<Integer> set = new HashSet<Integer>();
System.out.println("Program starting...");
System.out.print("Please enter in " + numbers.length + " numbers: ");
for (int i = 0; i < numbers.length; i++) {
set.add(input.nextInt());
}
for(Integer i : set)
{
System.out.println("" + i);
}
This will only add unique values to the set.
int a[] = { 2, 4, 5, 3, 3, 3, 4, 6 };
int flag = 0;
for (int i = 0; i < a.length; i++)
{
flag = 0;
for (int j = i + 1; j < a.length; j++)
{
if (a[i] == a[j])
{
flag = 1;
}
}
if (flag == 0)
{
System.out.println(a[i]);
}
}
I have an array, say
int a[]={2,0,1,0,1,1,0,2,1,1,1,0,1,0,1};
I need to append each of the 5 neighboring elements and assign them to a new array b with length=(a.length/5); and i want to append the 5 neighboring elements so that I have:
int b[]={20101,10211,10101}; I need to do this for various length arrays, in most cases with length of a being greater than 15.
Any help would be greatly appreciated, I'm programming in Java.
Thanks in advance.
It's pretty straighforward:
// Assuming a.length % 5 == 0.
int[] b = new int[a.length / 5];
for (int i = 0; i < a.length; i += 5) {
b[i/5] = a[i]*10000 + a[i+1]*1000 + a[i+2]*100 + a[i+3]*10 + a[i+4];
}
This sounds like a homework question, so I won't give you the complete solution, but the basic rundown is:
Compute the length of b: len = a.length / 5
Construct b with that many elements.
Initialize an index variable to point to the first element in a
For each element in b:
Construct the value for that element from a[idx]...a[idx+4]
Advance the index into a by 5.
Also note that you may need to verify that the input a is actually a multiple of 5 in length.
This works with (a.length % 5) != 0, and keeps leading zeroes (by storing digits into String).
int a[]={2,0,1,0,1,1,0,2,1,1,1,0,1,0,1,0,0,7};
final int N = 5;
String b[] = new String[(a.length + N - 1)/ N];
StringBuilder sb = new StringBuilder(N);
int x = 0;
for (int i = 0; i < b.length; i++) {
sb.setLength(0);
for (int k = 0; k < N && x < a.length; k++) {
sb.append(a[x++]);
}
b[i] = sb.toString();
}
System.out.println(java.util.Arrays.toString(b));
// prints "[20101, 10211, 10101, 007]"
Alternately, you can also use regex:
String[] arr =
java.util.Arrays.toString(a)
.replaceAll("\\D", "")
.split("(?<=\\G.{5})");
System.out.println(java.util.Arrays.toString(arr));
// prints "[20101, 10211, 10101, 007]"
Basically this uses Arrays.toString(int[]) to append all digits into one long String, then removes all non-digits \D, then uses \G-anchored lookbehind to split every .{5}
Naive approach.
import java.util.ArrayList;
/* Naive approach */
public class j2728476 {
public static void main(String[] args) {
int a[] = {2,0,1,0,1,1,0,2,1,1,1,0,1,0,1};
ArrayList<String> al = new ArrayList<String>();
String s = "";
for (int i = 0; i < a.length; i++) {
if (i % 5 == 0 && i != 0) {
al.add(s);
s = "" + a[i];
} else {
s += a[i];
}
}
al.add(s);
for (String t : al) {
// convert values to ints ...
System.out.println(t);
}
}
}
Will print:
20101
10211
10101
import java.util.Arrays;
public class MainClass {
public static void main(String args[]) throws Exception {
int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 };
Arrays.sort(array);
printArray("Sorted array", array);
int index = Arrays.binarySearch(array, 1);
System.out.println("Didn't find 1 # "
+ index);
int newIndex = -index - 1;
array = insertElement(array, 1, newIndex);
printArray("With 1 added", array);
}
private static void printArray(String message, int array[]) {
System.out.println(message
+ ": [length: " + array.length + "]");
for (int i = 0; i < array.length; i++) {
if (i != 0){
System.out.print(", ");
}
System.out.print(array[i]);
}
System.out.println();
}
private static int[] insertElement(int original[],
int element, int index) {
int length = original.length;
int destination[] = new int[length + 1];
System.arraycopy(original, 0, destination, 0, index);
destination[index] = element;
System.arraycopy(original, index, destination, index
+ 1, length - index);
return destination;
}
}
It will print
Sorted array: [length: 10]
-9, -7, -3, -2, 0, 2, 4, 5, 6, 8
Didn't find 1 # -6
With 1 added: [length: 11]
-9, -7, -3, -2, 0, 1, 2, 4, 5, 6, 8