Yahoo India Web Search

Search results

  1. www.hackerrank.com › challenges › cut-the-sticksCut the sticks - HackerRank

    You will iteratively cut the sticks into smaller sticks, discarding the shortest pieces until there are none left. At each iteration you will determine the length of the shortest stick remaining, cut that length from each of the longer sticks and then discard all the pieces of that shortest length.

  2. Jul 31, 2024 · In this HackerRank Cut the sticks problem you have Given the lengths of n sticks, print the number of sticks that are left before each iteration until there are none left.

  3. You will iteratively cut the sticks into smaller sticks, discarding the shortest pieces until there are none left. At each iteration you will determine the length of the shortest stick remaining, cut that length from each of the longer sticks and then discard all the pieces of that shortest length.

  4. 40 lines (30 loc) · 756 Bytes. #!/bin/python3 from collections import defaultdict import math import os import random import re import sys # # Complete the 'cutTheSticks' function below. # # The function is expected to return an INTEGER_ARRAY.

  5. // So we don't have to change the lengths every time! int n; int sticks [1000]; scanf ("%d",&n); for (int i=0;i<n;i++) scanf ("%d",&sticks [i]); sort (sticks,sticks+n); printf ("%d\n",n); for (int i=0;i<n;) { int cur = sticks [i]; while (sticks [i]==cur) i++; if (n!=i) printf ("%d\n",n-i); } return 0; }

  6. Space Complexity: O (n) //we need to create an extra array which keeps all the stick lengths in descending sorted order. */ using System; using System.Linq; class Solution { static void Main (String [] args) { var n = int.Parse (Console.ReadLine ()); var arr_temp = Console.ReadLine ().Split (' '); var sticks = Array.ConvertAll (arr_temp, Int32 ...

  7. Apr 8, 2023 · Problem statement : Cut the sticks | HackerRank. You are given a number of sticks of varying lengths. You will iteratively cut the sticks into smaller sticks… www.hackerrank.com. 'use...

  1. People also search for