এখানে দুটি লিস্ট দেওয়া আছে। আমাদের কাজ হলো চেক করা যে দুটি দেওয়া লিস্ট সার্কুলারলি ইডেন্টিক্যাল (circularly identical) কিনা।
উদাহরণ
Input : A = [100, 100, 10, 10, 100] B = [100, 100, 100, 10, 10] Output : True
ব্যাখ্যা
True কারণ যখন লিস্টের এলিমেন্টগুলো সার্কুলারলি রোটেট করা হবে তবে সেগুলো অন্য দেওয়া লিস্টের সাথে সাদৃশ্যপূর্ণ হয়ে যাবে।
অ্যালগরিদম
ধাপ ১: প্রথম এবং দ্বিতীয় লিস্ট তৈরি করুন। ধাপ ২: তারপর লিস্টগুলোকে ম্যাপে রূপান্তর করুন। ধাপ ৩: join() মেথড ব্যবহার করে লিস্ট অবজেক্টগুলোকে স্ট্রিং-এ রূপান্তর করুন। ধাপ ৩: লিস্ট A কে ডাবল করুন এবং ম্যাপে রূপান্তর করুন। ধাপ ৪: দুটি লিস্ট তুলনা করুন। যদি ফলাফল true হয় তবে দুটি লিস্ট সার্কুলারলি ইডেন্টিক্যাল এবং যদি false হয় তবে সার্কুলারলি নন-ইডেন্টিক্যাল।
উদাহরণ কোড
# পাইথন প্রোগ্রাম: দুটি লিস্ট সার্কুলারলি ইডেন্টিক্যাল কিনা চেক ও ভেরিফাই A=list() n=int(input("Enter the size of the First List ::")) print("Enter the Element of First List ::") for i in range(int(n)): k=int(input("")) A.append(k) B=list() n1=int(input("Enter the size of the Second List ::")) print("Enter the Element of the Second List ::") for i in range(int(n1)): k=int(input("")) B.append(k) C=list() n3=int(input("Enter the size of the Third List ::")) print("Enter the Element of the Third List ::") for i in range(int(n3)): k=int(input("")) C.append(k) print("Compare First List and Second List ::>") print(' '.join(map(str, B)) in ' '.join(map(str, A * 2))) print("Compare Second List and Third List ::>") print(' '.join(map(str, C)) in ' '.join(map(str, A * 2))) আউটপুট
Enter the size of the First List :: 5 Enter the Element of First List :: 10 10 0 0 10 Enter the size of the Second List :: 5 Enter the Element of the Second List :: 10 10 10 0 0 Enter the size of the Third List :: 5 Enter the Element of the Third List :: 1 10 10 0 0 Compare First List and Second List ::> True Compare Second List and Third List ::> False