Results 1 to 8 of 8

Thread: BuYS: Coding questions: Share/Save - My123World.Com!

  1. #1

    BuYS: Coding questions:

    Suppose u have two strings......A and B....... then how will u find out whether B is rotation of A or not??
    By rotation here what i mean is suppose A==GARAGE......... B=RAGEGA...... then B is the rotation of A..... RAGE IS NOT rotation of GARAGE.

    HINT: I know it can be done via long coding....... but it can also be a one-liner.....
    PS:dont google.. u vl get the ans.... or if some1 knows the trick... dont tell now u can write "I KNOW"....... for guys who dont know... plzz.. try....

    Time Frame: 2 days

    Lets take another example A====ORANGE:
    from character 'N'
    anticlock wise:B= NAROEG Its NOT
    CLOCLWISE: B=NGEORA........... ITS Rotation
    so we are considering her only Clockwise
    Last edited by s1ayer; 06-02-2011 at 10:39 PM.
    JAI MATA DI

    *

    Silence is not our weakness, Its just we dont want to waste our time...........

  2. #2
    Super Commando Dhruv abhaythehero's Avatar
    Join Date
    Sep 2010
    Location
    Lucknow/Pune,India
    Posts
    466
    Blog Entries
    2
    By rotation here what i mean is suppose A==GARAGE......... B=RAGEGA....... then B is the rotation of A
    but if B=RAGEGA... then it is not....
    these appear to be contradictory
    both place B=RAGEGA
    In the world of 0s and 1s, are you a zero or The One !

  3. #3
    Thanks for noticing :P actually i wanted to write them clockwise and anticlockwise.... from R....
    original: GARAGE
    anticlockwise: RAGEGA
    clockwise:RAGEGA
    both turned out to be same:
    Lets take another example ORANGE:
    from character 'N'
    anticlock wise: NAROEG Its NOT
    CLOCLWISE: NGEORA........... ITS Rotation
    so we are considering her only Clockwise
    JAI MATA DI

    *

    Silence is not our weakness, Its just we dont want to waste our time...........

  4. #4
    common guys... no reply.......
    JAI MATA DI

    *

    Silence is not our weakness, Its just we dont want to waste our time...........

  5. #5
    Super Commando Dhruv abhaythehero's Avatar
    Join Date
    Sep 2010
    Location
    Lucknow/Pune,India
    Posts
    466
    Blog Entries
    2
    Tried hard .. could'nt find the soln
    PASS
    In the world of 0s and 1s, are you a zero or The One !

  6. #6
    Here is the answer:
    return (A.length==B.length && (B.substring(A+A)))
    LOGIC HERE is: if u replicate the first string...... twice.... then if B is the rotation of A then B will automatically become the substring
    eg: A= ORANGE
    B=NGEORA
    A+A=ORANGEORANGE
    NOW check B is the substring of A+A........
    PS: above code is for java..... similar can be written for different lang.
    JAI MATA DI

    *

    Silence is not our weakness, Its just we dont want to waste our time...........

  7. #7
    Security Researcher fb1h2s's Avatar
    Join Date
    Jul 2010
    Location
    India
    Posts
    616
    Blog Entries
    32
    I also pass but that was a good one
    Hacking Is a Matter of Time Knowledge and Patience

  8. #8
    InfoSec Consultant the_empty's Avatar
    Join Date
    Jul 2010
    Location
    the blue no-where
    Posts
    155
    Blog Entries
    2
    awesome observations. such things are really good to build up your coding skills.

    thanks a ton
    ACCESS is GOD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •