Solution approach to Magician problem

I came across this problem titled “Magician” in some coding competition (it is over now). The statement is as follows, there is a stack of cards, say ABCDE, with A being on the top and E being the at the bottom. The first card is taken out and put on the table. The second card is lifted and kept at the bottom of the stack. This process is repeated until the stack is empty. As an example,

  • ABCDE (Initial)
  • A (on table), BCDE (on stack)
  • A (on table), CDEB (on stack)

The cards are numbered [1,N] and initially stacked in a way such that, after the process completes, the cards are arranged sequentially. Your task is to return the sequence/location number for a particular card K. As an example,

  • 142635
  • 1 (42635)
  • 1 (26354)
  • 1,2 (6354)
  • 1,2 (3546)
  • 1,2,3 (546)
  • 1,2,3 (465)
  • 1,2,3,4 (65)
  • 1,2,3,4 (56)
  • 1,2,3,4,5 (6)
  • 1,2,3,4,5,6

For,

  • K = 1, Ans:= 1
  • K = 2, Ans:= 3
  • K = 3, Ans:= 5
  • K = 4, Ans:= 2
  • K = 5, Ans:= 6
  • K = 6, Ans:= 4

What should the approach be to solve this problem?