Sort by

recency

|

172 Discussions

|

  • + 0 comments
    n,m = map(int, input().split())
    x= n*m
    if x ==1:
        print(0)
    else:
        print(x-1)
    
  • + 0 comments

    This is an interesting problem !

    Got stuck at 3/8 test cases ?

    • Think of it as single paper which need to be divided into N*M parts.
    • As per question one cut produces 1 extra part (1 page + 1 cut = 2 part of page now )
    • We need total of N*M parts since we already have 1 paper so just need N*M -1 more cuts to get our work done.
  • + 0 comments
    (n-1) + n(m-1)
    
  • + 1 comment

    I thought it like this - for a nXm size. First make (m-1) vertical cuts or (n-1) horizontal cuts then make (n-1)*m horizontal cuts or (m-1)n vertical cuts, respectively. Let me know if the explanation is not clear, will try to improve it.

    My golang solution

    func solve(n int32, m int32) int64 {
        return int64(m-1) + int64(n-1) * int64(m)
    }
    
  • + 0 comments

    This thing was a nightmare for me when I was studying. I always used the Bamboo method to solve such questions. You should learn that method, it helped me pass with good marks.