Josephus Problem Algorithm using Bit Manipulation | Bit Manipulation Interview Questions

Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we explain question Josephus Problem and discuss the algorithm to solve this problem using bit manipulation. In this problem,
1. You are given an integer N which represents the total number of soldiers standing in a circle having position marked from 1 to N.
2. A cruel king wants to execute them but in a different way.
3. He starts executing soldiers from 1st position and proceeds around the circle in clockwise direction.
4. In each step, every second soldier is executed.
5. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed soldiers are removed), until only the last soldier remains, who is given freedom.
6. You have to find the position of that lucky soldier.
Click here to submit this question: www.pepcoding.com/resources/d...
For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
#josephus #bitmanipulation #competitiveprogramming
Have a look at our result: www.pepcoding.com/placements
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
Join us on Telegram: t.me/joinchat/UVTjJE83a-zFnPB

Пікірлер: 43

  • @sanjanasanikommu7873
    @sanjanasanikommu78733 жыл бұрын

    the patience with which u tried to explain the prob by giving extra example at 16.41 is jus wow!!

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Glad to know that you liked the content and thank you for appreciating. The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos. So, keep motivating, keep learning and keep loving Pepcoding😊

  • @vatsalmehta7159
    @vatsalmehta71592 жыл бұрын

    Pepcoding content much better than other ed-tech startups🔥🔥🔥

  • @sahiljain2524
    @sahiljain25243 жыл бұрын

    Best Explanation sab bus circle bana ke bata dete the concept koi na deta tha. Thanks !

  • @Tensor08
    @Tensor08 Жыл бұрын

    love the patience you have and the way you teach, just Wowww

  • @aniruddhachunne3011
    @aniruddhachunne30112 жыл бұрын

    Awesome explanation of concept sir.. hatts off to you... god bless you forever... you are better than most costly tutor of DSA

  • @indranilchakraborty5949
    @indranilchakraborty59493 жыл бұрын

    Excellent quality ❤🙏🙏

  • @ananyaarya2465
    @ananyaarya24653 жыл бұрын

    video ko 4 baar dekha lekin finally samajh aagaya,tysm sir :-)

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Glad it was helpful!! share as much as you can and it will be nice if you can write a post about us on LinkedIn

  • @ananyaarya2465

    @ananyaarya2465

    3 жыл бұрын

    @@Pepcoding sure sir!

  • @AMBUJ6

    @AMBUJ6

    Жыл бұрын

    @@ananyaarya2465 from where I should learn Java language

  • @trglegend6287
    @trglegend6287 Жыл бұрын

    1 no sir

  • @premgarg5534
    @premgarg5534 Жыл бұрын

    Awesome video. So much effort. Unfortunately, didn't get it even after repeating it multiple times

  • @aaravrubral363
    @aaravrubral3633 жыл бұрын

    Amazing sir

  • @Beingyash7
    @Beingyash73 жыл бұрын

    THE LEGEND !

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Glad to know that you liked the content and thank you for appreciating. The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos. So, keep motivating, keep learning and keep loving Pepcoding😊

  • @mickyman753
    @mickyman7532 жыл бұрын

    sir josephus ke kya aur bhi special cases hai ,if yes toh pls video bna dijiye sir

  • @arnabdutta4662
    @arnabdutta46622 жыл бұрын

    I was expecting that you might have done this using bit-manipulation taking 'k' into account .

  • @vaibhavgupta6600
    @vaibhavgupta6600 Жыл бұрын

    sir is there any bit method for kth number case?

  • @ghanibhai1630
    @ghanibhai16302 жыл бұрын

    sir we can also make formula for all cases not only for 2

  • @RahulSharma-ip3pc
    @RahulSharma-ip3pc Жыл бұрын

    Other solution can be n

  • @mickyman753
    @mickyman7532 жыл бұрын

    using recusrion solution would be useless as numbers on portal are huge so stack overflow

  • @pulkitkks
    @pulkitkks3 жыл бұрын

    Very helpful video sir, but I have a doubt. What is the complexity of Math.log() function. If it is O(1) then we can calculate powerOf2 in O(1) also, by using log function. Thereby, reducing the complexity of whole solution to O(1). int logBase2 = (int)(Math.log(n) / Math.log(2)); int powerOf2 = 1

  • @yashkushwaha8492

    @yashkushwaha8492

    3 жыл бұрын

    it's O(logn)

  • @chhawinderpreetsingh8251
    @chhawinderpreetsingh8251 Жыл бұрын

    c++k liye nhi work krta website sir

  • @ashwinnema06
    @ashwinnema062 жыл бұрын

    Nice explanation sir

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Keep watching. For better experience and precisely arranged content visit on nados.io

  • @vyomchandragallani3645
    @vyomchandragallani36452 жыл бұрын

    but if i put k=2 in josephus problem, it gives wrong answers, can you explain why? in (solution(n-1)+k)%n

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    For better insight, visit nados.pepcoding.com, post your doubts, community will help you out there.

  • @amandixit3555
    @amandixit35553 жыл бұрын

    sir isme kernigham ka logic kahan use kiya, apne vedio ki statrting mei kaha tha ki karnigham ka algo use karenge

  • @simon8284

    @simon8284

    2 жыл бұрын

    Bhai playlist ke upar vale vdo me hai vo... Ye me dekh ra hu sab DSA ka aisa lagta hai ratne ka kaam jesa lag ra ye sab formula algo... Ye ek ek algo me to unhone kitna months lagaya hoga... Aur hamse expect krte hai k solve krr de Bina solution ke matlub yaar jisne ek baar go through kiya ho in sab se vahi interview crack kr paye...

  • @mayankkhatri6826
    @mayankkhatri68262 жыл бұрын

    how to think this type of concept in dsa round in placement

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Please visit nados.pepcoding.com and post your query there our community will help you out.

  • @rahulbhatia3075
    @rahulbhatia30753 жыл бұрын

    Sir when every kth person dies, then what will be the formula?

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    That question is already done in backtracking. Please check.

  • @rahulbhatia3075

    @rahulbhatia3075

    3 жыл бұрын

    @@Pepcoding which question sir?

  • @indranilchakraborty5949

    @indranilchakraborty5949

    3 жыл бұрын

    @@rahulbhatia3075 Joseph's problem bol kr hai

  • @algoconqueror3579
    @algoconqueror3579 Жыл бұрын

    OP

  • @shivangagrawal2923
    @shivangagrawal29232 жыл бұрын

    nice explanation but wrong when n=4

  • @theuntoldtree
    @theuntoldtree2 жыл бұрын

    thoda km smjh aaya last ka analysis

  • @yugsoni2603
    @yugsoni26033 жыл бұрын

    God Mode

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Thankyou beta! I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @RAHULROY-sb9nt
    @RAHULROY-sb9nt2 жыл бұрын

    Survey says only 6-7 percentage of people are intelligent or they are willing to be..so this is the reason for your less subscriber.

Келесі