code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

Frequenciesinsortedarray

/**
 *
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

class FrequenciesInSortedArray {

  static void func(int[] nums){
    int frequenices = 1;
    int start = 1;
    int end = nums.length;
    while(start < end){
      while(start < end && nums[start] == nums[start - 1]){
        frequenices += 1;
        start += 1;
      }
      System.out.println(String.format("%d - %d", nums[start-1], frequenices));
      start += 1;
      frequenices = 1;
    }
  }

  public static void main(String[] args){
    int[] nums = {10, 10, 10, 25, 30, 30};
    func(nums);
  }
}

Created 2021-10-28T01:03:41+01:00 · Edit