#42 Delete occurrences of an element if it occurs more than n times



Enough is enough!

Alice and Bob were on a holiday. Both of them took many pictures of the places they've been, and now they want to show Charlie their entire collection. However, Charlie doesn't like this sessions, since the motive usually repeats. He isn't fond of seeing the Eiffel tower 40 times. He tells them that he will only sit during the session if they show the same motive at most N times. Luckily, Alice and Bob are able to encode the motive as a number. Can you help them to remove numbers such that their list contains each number only up to N times, without changing the order?


Task

Given a list lst and a number N, create a new list that contains each number of lst at most N times without reordering. For example if N = 2, and the input is [1,2,3,1,2,1,2,3], you take [1,2,3,1,2], drop the next [1,2] since this would lead to 1 and 2 being in the result 3 times, and then take 3, which leads to [1,2,3,1,2,3].


Example

EnoughIsEnough.deleteNth(new int[] {20,37,20,21}, 1) // return [20,37,21]

EnoughIsEnough.deleteNth(new int[] {1,1,3,3,7,2,2,2,2}, 3) // return [1, 1, 3, 3, 7, 2, 2, 2]



#41 Dashatize it

 

 

Given a number, return a string with dash'-'marks before and after each odd integer, but do not begin or end the string with a dash mark.

 

Ex:
dashatize(274) -> '2-7-4'
dashatize(6815) -> '68-1-5'

 

#38  Highest Scoring Word


Given a string of words, you need to find the highest scoring word.


Each letter of a word scores points according to it's position in the alphabet: a = 1, b = 2, c = 3 etc.


You need to return the highest scoring word as a string.


If two words score the same, return the word that appears earliest in the original string.


All letters will be lowercase and all inputs will be valid.




#36 The Supermarket Queue 


There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!


The function has two input variables:


customers: an array (list in python) of positive integers representing the queue. Each integer represents a customer, and its value is the amount of time they require to check out.

n: a positive integer, the number of checkout tills.

The function should return an integer, the total time required.


EDIT: A lot of people have been confused in the comments. To try to prevent any more confusion:


There is only ONE queue, and

The order of the queue NEVER changes, and

Assume that the front person in the queue (i.e. the first element in the array/list) proceeds to a till as soon as it becomes free.

The diagram on the wiki page I linked to at the bottom of the description may be useful.

So, for example:


queueTime([5,3,4], 1)

// should return 12

// because when n=1, the total time is just the sum of the times


queueTime([10,2,3,3], 2)

// should return 10

// because here n=2 and the 2nd, 3rd, and 4th people in the 

// queue finish before the 1st person has finished.


queueTime([2,3,10], 2)

// should return 12



#34 Write Number in Expanded Form


Write Number in Expanded Form

You will be given a number and you will need to return it as a string in Expanded Form. For example:


Kata.expandedForm(12); # Should return "10 + 2"

Kata.expandedForm(42); # Should return "40 + 2"

Kata.expandedForm(70304); # Should return "70000 + 300 + 4"

NOTE: All numbers will be whole numbers greater than 0.



#33 Vasya - Clerk


The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill. An "Avengers" ticket costs 25 dollars.


Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.


Can Vasya sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?


Return YES, if Vasya can sell a ticket to each person and give the change with the bills he has at hand at that moment. Otherwise return NO.


###Examples:


// *** Java ***


Line.Tickets(new int[] {25, 25, 50}) // => YES 

Line.Tickets(new int []{25, 100}) 

         // => NO. Vasya will not have enough money to give change to 100 dollars




	  public static String Tickets(int[] peopleInLine) {
		  
	      //Your code is here...
		  int dollars25 = 0;
		  int dollars50 = 0;
		  
		  for (int i : peopleInLine) {
			  if(i==25) {
				  dollars25++;
			  }else if(i==50) {
				  dollars25--;
				  dollars50++;
			  }else {
				  if(dollars50>0) {
					  dollars50--;
					  dollars25--;
				  }else {
					  dollars25 -=3;
				  }
			  }
			  if (dollars25<0 || dollars50<0) return "NO";
		  }
		  return "YES";
	  }

 #31 extract file name


ou have to extract a portion of the file name as follows:


Assume it will start with date represented as long number

Followed by an underscore

Youll have then a filename with an extension

it will always have an extra extension at the end

Inputs:

1231231223123131_FILE_NAME.EXTENSION.OTHEREXTENSION


1_This_is_an_otherExample.mpg.OTHEREXTENSIONadasdassdassds34


1231231223123131_myFile.tar.gz2

Outputs

FILE_NAME.EXTENSION


This_is_an_otherExample.mpg


myFile.tar

The recommend way to solve it is using RegEx and specifically groups.



'매일매일개발 > Codewars' 카테고리의 다른 글

codewars #33 Vasya - Clerk (6kyu)  (1) 2018.05.02
codewars #32 Dubstep (6kyu)  (0) 2018.05.01
codewars #30 Psychic (3kyu)  (1) 2018.04.27
codewars #29 Multiples of 3 or 5 (6kyu)  (0) 2018.04.26
codewars #28 Valid Braces (4kyu)  (1) 2018.04.25

#30 Psychic


A common exercise, when you're learning a new language, is to make a guessing game. It's a great way to learn control structures, IO, the works.


This is taking the guessing game to a whole new level. This time, you're the one playing the guessing game. And the guessing game is Math.random().


The task is really simple. You make a guess, Math.random() does it's thing, and if you're right 5 times out of 5, you win!


Hint: You guess first.



#27 Follow that Spy


We are tracking down our rogue agent Matthew Knight A.K.A. Roy Miller and he travels from places to places to avoid being tracked. Each of his travels are based on a list of itineraries in an unusual or incorrect order. The task is to determine the routes he will take in his every journey. You are given an array of routes of his itineraries. List down only the places where he will go in correct order based on his itineraries.


Example:

routes = [[USA, BRA], [JPN, PHL], [BRA, UAE], [UAE, JPN]]


result: "USA, BRA, UAE, JPN, PHL"


note: It is safe to assume that there will be no repeating place with different rout



'매일매일개발 > Codewars' 카테고리의 다른 글

codewars #29 Multiples of 3 or 5 (6kyu)  (0) 2018.04.26
codewars #28 Valid Braces (4kyu)  (1) 2018.04.25
오늘은 하루 쉼  (0) 2018.04.23
codewars #26 lucky number (7kyu)  (1) 2018.04.20
codewars #25 Find The Parity Outlier (6kyu)  (0) 2018.04.19

#25 Find The Parity Outlier



You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N.


Examples

[2, 4, 0, 100, 4, 11, 2602, 36]

Should return: 11 (the only odd number)


[160, 3, 1719, 19, 11, 13, -21]

Should return: 160 (the only even number)



'매일매일개발 > Codewars' 카테고리의 다른 글

오늘은 하루 쉼  (0) 2018.04.23
codewars #26 lucky number (7kyu)  (1) 2018.04.20
codewars #24 A + B == 123 (6kyu)  (0) 2018.04.18
codewars #23 Prime Streaming (NC-17) (2kyu)  (1) 2018.04.17
codewars #22 Fat Fingers (5kyu)  (0) 2018.04.16

+ Recent posts