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
the patience with which u tried to explain the prob by giving extra example at 16.41 is jus wow!!
@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😊
Pepcoding content much better than other ed-tech startups🔥🔥🔥
Best Explanation sab bus circle bana ke bata dete the concept koi na deta tha. Thanks !
love the patience you have and the way you teach, just Wowww
Awesome explanation of concept sir.. hatts off to you... god bless you forever... you are better than most costly tutor of DSA
Excellent quality ❤🙏🙏
video ko 4 baar dekha lekin finally samajh aagaya,tysm sir :-)
@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
3 жыл бұрын
@@Pepcoding sure sir!
@AMBUJ6
Жыл бұрын
@@ananyaarya2465 from where I should learn Java language
1 no sir
Awesome video. So much effort. Unfortunately, didn't get it even after repeating it multiple times
Amazing sir
THE LEGEND !
@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😊
sir josephus ke kya aur bhi special cases hai ,if yes toh pls video bna dijiye sir
I was expecting that you might have done this using bit-manipulation taking 'k' into account .
sir is there any bit method for kth number case?
sir we can also make formula for all cases not only for 2
Other solution can be n
using recusrion solution would be useless as numbers on portal are huge so stack overflow
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
3 жыл бұрын
it's O(logn)
c++k liye nhi work krta website sir
Nice explanation sir
@Pepcoding
2 жыл бұрын
Keep watching. For better experience and precisely arranged content visit on nados.io
but if i put k=2 in josephus problem, it gives wrong answers, can you explain why? in (solution(n-1)+k)%n
@Pepcoding
2 жыл бұрын
For better insight, visit nados.pepcoding.com, post your doubts, community will help you out there.
sir isme kernigham ka logic kahan use kiya, apne vedio ki statrting mei kaha tha ki karnigham ka algo use karenge
@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...
how to think this type of concept in dsa round in placement
@Pepcoding
2 жыл бұрын
Please visit nados.pepcoding.com and post your query there our community will help you out.
Sir when every kth person dies, then what will be the formula?
@Pepcoding
3 жыл бұрын
That question is already done in backtracking. Please check.
@rahulbhatia3075
3 жыл бұрын
@@Pepcoding which question sir?
@indranilchakraborty5949
3 жыл бұрын
@@rahulbhatia3075 Joseph's problem bol kr hai
OP
nice explanation but wrong when n=4
thoda km smjh aaya last ka analysis
God Mode
@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 )
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.