• Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
CODE OF GEEKS

We at CODE OF GEEKS, aim at providing best and quality content for our users at no extra cost.

    • Study Materials – Company wise
      • Infosys Archive
      • Accenture Archive
      • AMCAT Archive
      • Capgemini Archive
      • Cisco Archive
      • CoCubes Archive
      • Cognizant(CTS) Archive
      • Dell Archive
      • Deloitte Archive
      • DXC Archive
      • Goldman Sachs Archive
      • Hexaware Technologies Archive
      • LTI Archive
      • MindTree Archive
      • TCS Archive
      • Virtusa Archive
      • Wipro Archive
    • Interview Preparation – E Books
      • C Interview Questions
      • Data Structures Interview Questions
      • DBMS Interview Questions
      • HR Interview Questions
      • Java Interview Questions
      • Operating System Interview Questions
      • Python Interview Questions
      • SQL Query Interview Questions
    • Programming
      • C Programming MCQs
      • C Code Snippets – Output Questions
      • Python Code Snippets – Output Questions
    • Aptitude
      • Verbal Ability for Placements
      • Quant for Placements
    • Register
    • Login
  • [email protected]
  • ..
Login / Register
Apply Now
CODE OF GEEKS
CODE OF GEEKS
  • Study Materials – Company wise
    • Infosys Archive
    • Accenture Archive
    • AMCAT Archive
    • Capgemini Archive
    • Cisco Archive
    • CoCubes Archive
    • Cognizant(CTS) Archive
    • Dell Archive
    • Deloitte Archive
    • DXC Archive
    • Goldman Sachs Archive
    • Hexaware Technologies Archive
    • LTI Archive
    • MindTree Archive
    • TCS Archive
    • Virtusa Archive
    • Wipro Archive
  • Interview Preparation – E Books
    • C Interview Questions
    • Data Structures Interview Questions
    • DBMS Interview Questions
    • HR Interview Questions
    • Java Interview Questions
    • Operating System Interview Questions
    • Python Interview Questions
    • SQL Query Interview Questions
  • Programming
    • C Programming MCQs
    • C Code Snippets – Output Questions
    • Python Code Snippets – Output Questions
  • Aptitude
    • Verbal Ability for Placements
    • Quant for Placements
  • Register
  • Login
0

Cart

String Rotation

  • March 1, 2020
  • CODE OF GEEKS
  • 6

A rotation on a string is defined as removing first element and concatenating it at the end.

Given N and an array of N strings.
Your job is to predict the minimum no. of rotations on the strings so as to make all the strings equal.
If this is not possible return -1



Example

Input

4
11234
34112
41123
11234

Output

3



Tags: hack with infy coding questionshackwithinfy coding problemshackwithinfy coding questions
  • Previous m*n board
  • Next Even-Odd Problem

6 comments on “String Rotation”

  1. Vamsidhar Reddy says:
    March 12, 2020 at 2:31 pm

    the no.of rotations will be n-1 for every case

    Reply
    1. padma says:
      March 15, 2020 at 3:08 am

      can you give answer in python plss

      Reply
      1. Chethan N says:
        May 28, 2020 at 4:21 pm

        def rotation(a,b):
        if a==b:
        return 0
        temp=b+b
        for i in range(len(b)):
        if temp[i:i+len(b)]==a:
        return i
        else:
        return -1
        def min_string(a):
        dic={}
        maps=a[0]+a[0]
        for i in range(len(a[0])):
        dic[maps[i:i+len(a[0])]]=0
        for ele in a:
        for key in dic.keys():
        dic[key]+=rotation(key,ele)
        print(min(dic.values()))
        min_string([“xzzwo”, “zwoxz”, “zzwox”, “xzzwo”] )

        Reply
  2. Pingback: How to Prepare for Hack with Infy 2020 Round 2 - CODE OF GEEKS
  3. devansh mathur says:
    May 27, 2020 at 12:12 pm

    l=[“123”, “231”, “231”, “123”]
    hash={}
    hash1={}
    temp=[]
    temp.append((0,l[0]))
    hash1[l[0]]=0
    for j in range(1,len(l[0])):
    rot=l[0][j:]+l[0][0:j]
    hash1[rot]=j
    temp.append((j,rot))
    hash[l[0]]=temp
    def solve(hash,hash1,l):
    try:
    for i in range(1,len(l)):
    temp=[]
    temp.append((l[i],0))
    hash1[l[i]]+=0
    for j in range(1,len(l[i])):
    rot=l[i][j:]+l[i][0:j]
    hash1[rot]+=j
    temp.append((j,rot))
    hash[l[i]]=temp
    return min(hash1.values())
    except:
    return -1
    print(solve(hash,hash1,l))

    #ignore hash dictionary just used it to debug nd track

    Reply
  4. Dhinesh says:
    May 30, 2020 at 4:20 pm

    Solution
    https://pastebin.com/Z8eXnPvy

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CODE OF GEEKS

Subscribe to Newsletter

CODE OF GEEKS

Learn | Code | Achieve

Reach us

[email protected]
We at CODE OF GEEKS, aim at providing quality content to our users at no cost.
CODE OF GEEKS

Important Pages

About us
Advertise
Privacy Policy
Terms and Conditions

Placements – Study Materials

TCS NQT     Wipro     CapGemini
Accenture     MindTree     CTS
DXC     Hexaware Technologies     AMCAT
CoCubes     Goldman Sachs     Dell
Cisco     Deloitte     Virtusa     LTI     Infosys   

Courses

  • Mail Us
  • Login/Register

Recent Posts

What is Cloud Computing | Cloud Computing Applications | Cloud Development Models| SaaS vs PaaS vs IaaS
  • October 23, 2021
What is Amazon Web Services | AWS Regions & AZs | Different AWS Services
  • October 19, 2021

Copyright 2021 CODE OF GEEKS. All Rights Reserved.

  • →