GithubHelp home page GithubHelp logo

maven.duplicatedeleter's Introduction

Delete Duplicates

  • Objective

    • To write methods which remove duplicate elements from an array.
  • Purpose

    • To demonstrate practical understanding of arrays, loops, and basic composition.
  • Instructions

    • Given an object, IntegerDuplicateDeleter, with a composite Integer[] object, write a method
      • removeDuplicatesExactly which removes all values in the array which occur exactly the specified number of times.
      • removeDuplicates which removes all values in the array which occur at least the specified number of times.

    • Given an object, StringDuplicateDeleter, with a composite String[] object, write a method
      • removeDuplicatesExactly which removes all values in the array which occur exactly the specified number of times.
      • removeDuplicates which removes all values in the array which occur at least the specified number of times.
  • Restrictions

    • No use of any built-in data structures, (Collection, List, Map)
    • Operations should be idempotent
      • If the input is the same, then the outputs of the methods should always be the same, regardless of how many times the method is called.





removeDuplicateExactly(n)

Example 1

  • Sample Script

    // : Given
    Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
    DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
    
    // : When
    Integer[] actual = deleter.removeDuplicateExactly(3);
    
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [23,23,56,57,58]
    

Example 2

  • Sample Script

    // : Given
    Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
    DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
    
    // : When
    Integer[] actual = deleter.removeDuplicateExactly(1);
    
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [1,1,1,23,23]
    

Example 3

  • Sample Script

    // : Given
    Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
    DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
    
    // : When
    Integer[] actual = deleter.removeDuplicateExactly(3);
    
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [1, 1, 2, 4, 4, 5, 5, 5, 5]
    





removeDuplicates(n)

Example 1

  • Sample Script

    // : Given
    Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
    DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
    
    // : When
    Integer[] actual = deleter.removeDuplicateExactly(1);
    
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    []
    

Example 2

  • Sample Script

    // : Given
    Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
    DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
    
    // : When
    Integer[] actual = deleter.removeDuplicates(2);
    
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [2]
    

Example 3

  • Sample Script

    // : Given
    Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
    DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
    
    // : When
    Integer[] actual = deleter.removeDuplicates(3);
    
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [1,1,2,4,4]
    





Idempotence

Example 1

  • Sample Script

    // : Given
    Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
    DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
    deleter.removeDuplicates(0);
    deleter.removeDuplicates(1);
    deleter.removeDuplicates(2);
    
    // : When
    Integer[] actual = deleter.removeDuplicates(3);
    
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [1,1,2,4,4]
    

Example 2

  • Sample Script

    // : Given
    Integer[] array = new Integer[]{1,1,1,23,23,56,57,58};
    DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
    deleter.removeDuplicates(0);
    deleter.removeDuplicates(1);
    deleter.removeDuplicates(2);
    
    // : When
    Integer[] actual = deleter.removeDuplicatesExactly(3);
    
    // : Then
    System.out.println(Arrays.toString(actual));
    
  • Sample Output

    [23,23,56,57,58]
    

maven.duplicatedeleter's People

Contributors

git-leon avatar leon-good-life avatar miscbits avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.