crazy helix hackerrank solution

public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        int[] arr = new int[n];
        for(int ar_i = 0; ar_i < n; ar_i++){
            arr[ar_i] = ar_i+1;
        }
        for(int ind=1;ind<=q+1;ind++){
            int a = in.nextInt();
            if(1==a){
                reverseSubArray(arr, in.nextInt()-1, in.nextInt()-1);
            }else if(2==a){
                int b = in.nextInt();
                for(int i=0;i<arr.length;i++){
                    if(arr[i]==b){
                        System.out.println("element "+ b +" is at position "+ (i+1));
                        break;
                    }
                }
            }else if(3==a){
                int b = in.nextInt();
                System.out.println("element at position " + b +  " is " + arr[b-1]);
            }
        }
    }
    
    static void reverseSubArray(int arr[], int i, int j){
        if(i>=j) return;
		for(;i<j;i++,j--){
			int temp = arr[i];
			arr[i]=arr[j];
			arr[j]=temp;
		}
    }

3.89
9
Awgiedawgie 440220 points

                                    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
int main()
{
int n,q,x,y,z,t;
scanf(&quot;%d %d&quot;,&amp;n,&amp;q);
int a[n];
for(int i=0;i&lt;n;i++)
{
    a[i]=i+1;
}
for(int j=0;j&lt;q;j++)
{
    scanf(&quot;%d&quot;,&amp;x);
    if(x==1)
    {
        int temp=0;
        scanf(&quot;%d&quot;,&amp;y);
        scanf(&quot;%d&quot;,&amp;z);
        t=z-y+1;
        y--;
        z--;

            for(int j=0;j&lt;t/2;j++)
            {
                 temp=a[y+j];
                a[y+j]=a[z-j];
                a[z-j]=temp;
            }

    else if(x==2)
        {
            int t=0;
           scanf(&quot;%d&quot;,&amp;y); 
          for(int i=0;i&lt;n;i++)
          {
              if(a[i]==y)
              {
                  t=i;
                  break;
              }
          }
          printf(&quot;element %d is at position %d\n&quot;,y,t+1);
        }
     else
        {
           scanf(&quot;%d&quot;,&amp;y); 
            printf(&quot;element at position %d is %d \n&quot;,y,a[y-1]);
        }

}
return 0;

3.89 (9 Votes)
0
3.67
3
Krish 100200 points

                                    n,queries=map(int,input().split())
num=[i+1 for i in range(n)]
for i in range(queries):
    l=list(map(int,input().split()))
    if len(l)==3:
        if l[1]==1:
            num=num[:l[1]-1]+num[l[2]-1::-1]+num[l[2]:]//1
        else:
            num=num[:l[1]-1]+num[l[2]-1:l[1]-2:-1]+num[l[2]:]//1
    elif l[0]==2:
        print(&quot;element {0} is at position {1}&quot;.format(l[1],num.index(l[1])+1))//2
    else:
        print(&quot;element at position {0} is {1}&quot;.format(l[1],num[l[1]-1]))

3.67 (3 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source