Skip to content

Instantly share code, notes, and snippets.

@houssemzaier
Created July 29, 2020 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save houssemzaier/c5054b9ef31d7af611c3674044152f4c to your computer and use it in GitHub Desktop.
Save houssemzaier/c5054b9ef31d7af611c3674044152f4c to your computer and use it in GitHub Desktop.
algo test for arc() dev
package fr.francetv.francetvsport.arch.infrastructure.data.source.remote.pic
//Your task is to split the chocolate bar of given dimension n x m into small squares.
//Each square is of size 1x1 and unbreakable. Implement a function that will return minimum number of breaks needed.
//
//For example, if you are given a chocolate bar of size 2 x 1 you can split it to single squares in just one break, but for size 3 x 1 you must perform two breaks.
//
//If input data is invalid you should return 0 (as in no breaks are needed if we do not have any chocolate to split). Input will always be a non-negative integer.
fun breakChocolate(n: Int, m: Int): Int = if ((n in 0..1) && (m in 0..1)) {
0
} else {
(n * m) - 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment