Hitachi Data Systems Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

package main

import "fmt"

type LList struct {
	Value int
	Next  *LList
}

func Print(head *LList) {
	for head != nil {
		fmt.Printf("%d ", head.Value)
		head = head.Next
	}
	fmt.Println()
}

func Revers(head *LList, K int) *LList {
	oldHead := head
	newHead := head
	var next, nextNext *LList
	if head != nil {
		next = head.Next
	}
	if next != nil {
		nextNext = next.Next
	}
	head.Next = nil
	for next != nil {
		next.Next = head
		if nextNext != nil {
			head, next, nextNext = next, nextNext, nextNext.Next
		} else {
			head, next, nextNext = next, nextNext, nil
		}
		K--
		if K > 0 {
			newHead = head
		}
		if K == 0 {
			head.Next = nil
		}
	}
	if K > 0 {
		return head
	}
	oldHead.Next = head
	return newHead
}

func main() {
	head := &LList{Value: 1}
	n2 := &LList{Value: 2}
	n3 := &LList{Value: 3}
	n4 := &LList{Value: 4}
	n5 := &LList{Value: 5}
	head.Next = n2
	n2.Next = n3
	n3.Next = n4
	n4.Next = n5
	Print(head)
	Print(Revers(head, 3))
}

- dmitry.labutin April 29, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static Node reverse(Node head, int k) {
			Node temp = head;
			Node prevTemp = temp;
			Node out = null;
			Node newNode = null;
			if (head != null)
			{
			
				temp = head;
				int i = 0;
				while (temp.Next!=null) {
					if(i == k)
						break;
					prevTemp = temp;
					temp = temp.Next;
					i++;
				}
				prevTemp.Next = null;
				newNode = reverse(head);
				out = merge(newNode,temp);
					
			}
			return out;
		}

		public static Node reverse(Node node) {
			if (node == null)
				return null;
			else if (node.Next == null)
				return node;
			else {

				Node second = node.Next;
				node.Next = null;
				Node reverseRest = reverse(second);
				second.Next = node;
				return reverseRest;

			}

		}
		
	
	
		private static Node merge(Node node1, Node node2) { // 3,2,1 -- 4,5
			Node temp = node1;
			if(temp.Next == null)
				return temp.Next = node2;
			else {
				merge(temp.Next, node2);
			}
			return temp;
			
		}

- Anonymous April 30, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static Node reverse(Node head, int k) {
			Node temp = head;
			Node prevTemp = temp;
			Node out = null;
			Node newNode = null;
			if (head != null)
			{
			
				temp = head;
				int i = 0;
				while (temp.Next!=null) {
					if(i == k)
						break;
					prevTemp = temp;
					temp = temp.Next;
					i++;
				}
				prevTemp.Next = null;
				newNode = reverse(head);
				out = merge(newNode,temp);
					
			}
			return out;
		}
	public static Node reverse(Node node) {
			if (node == null)
				return null;
			else if (node.Next == null)
				return node;
			else {

				Node second = node.Next;
				node.Next = null;
				Node reverseRest = reverse(second);
				second.Next = node;
				return reverseRest;

			}

		}
		private static Node merge(Node node1, Node node2) { // 3,2,1 -- 4,5
			Node temp = node1;
			if(temp.Next == null)
				return temp.Next = node2;
			else {
				merge(temp.Next, node2);
			}
			return temp;
			
		}

- xyz April 30, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* head;
void Insert(int a){
struct Node* temp1= (struct Node*)malloc(sizeof(struct Node));
temp1->data=a;
temp1->next=NULL;
if(head==NULL)
{
head=temp1;
return;
}
struct Node* temp2=head;
while(temp2->next!=NULL){
temp2=temp2->next;
}
temp2->next=temp1;
return;
}
void Print(){
struct Node* temp=head;
while(temp!=NULL){
printf(" %d",temp->data);
temp=temp->next;
}
}
struct Node* grprev(struct Node* start, int k){
struct Node* prev=NULL;
struct Node* curr=start, *next;
int i;
for(i=1;i<=k&&curr!=NULL;i++){
next=curr->next;
curr->next=prev;
prev=curr;
curr=next;
}
start->next=curr;
if(start==head){
head=prev;
}
return prev;
}
int main()
{
head=NULL;
Insert(1);
Insert(2);
Insert(3);
Insert(4);
Insert(5);
Print();
printf(" \n");
struct Node* temp=head, *temp1;
grprev(temp,3);
while(temp->next!=NULL)
{
temp1=temp->next;
temp->next=grprev(temp1,3);
temp=temp1;
}
Print();
printf(" \n");
return 0;
}

- Abhishek Paandey July 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void pushBack(Node **dest, Node **src)
{
Node *tmp=*src;
if(!tmp) return;
*src=tmp->next;
tmp->next=*dest;
*dest=tmp;
}





void blockReverse(Node **head, int count)
{
// reverse count nodes
int i=1;
Node *trav=*head;
Node *first_node;
Node *res=NULL,*prev=NULL;
int end=0,first=0;
while(trav &&!end)
{
for(i=1;i<=count;i++)
{
if(trav==NULL)
{
end=1;
} else {
pushBack(&(res),&trav);
}

}
//traverse res count times;
if(prev == NULL) {prev=res;}
else {
while(prev->next) prev=prev->next;
prev->next=res;
while(prev->next) prev=prev->next;
}
if(first==0) {
first_node=res;
first=1;
}
res=NULL;

}
*head=first_node;
}

- Giri April 10, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void pushBack(Node **dest, Node **src)
{
        Node *tmp=*src;
        if(!tmp) return;
        *src=tmp->next;
        tmp->next=*dest;
        *dest=tmp;
}


void blockReverse(Node **head, int count)
{
        // reverse count nodes
        int i=1;
        Node *trav=*head;
        Node *first_node;
        Node *res=NULL,*prev=NULL;
        int end=0,first=0;
        while(trav &&!end)
        {
                for(i=1;i<=count;i++)
                {
                        if(trav==NULL)
                        {
                                end=1;
                        } else {
                                pushBack(&(res),&trav);
                        }

                }
                //traverse res count times;

              if(prev == NULL) {prev=res;}
                else {
                        while(prev->next) prev=prev->next;
                        prev->next=res;
                        while(prev->next) prev=prev->next;
                }
                if(first==0) {
                        first_node=res;
                                first=1;
                }
                res=NULL;

        }
        *head=first_node;
}

- Giri April 10, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void pushBack(Node **dest, Node **src)
{
        Node *tmp=*src;
        if(!tmp) return;
        *src=tmp->next;
        tmp->next=*dest;
        *dest=tmp;
}


void blockReverse(Node **head, int count)
{
        // reverse count nodes
        int i=1;
        Node *trav=*head;
        Node *first_node;
        Node *res=NULL,*prev=NULL;
        int end=0,first=0;
        while(trav &&!end)
        {
                for(i=1;i<=count;i++)
                {
                        if(trav==NULL)
                        {
                                end=1;
                        } else {
                                pushBack(&(res),&trav);
                        }

                }
                //traverse res count times;

              if(prev == NULL) {prev=res;}
                else {
                        while(prev->next) prev=prev->next;
                        prev->next=res;
                        while(prev->next) prev=prev->next;
                }
                if(first==0) {
                        first_node=res;
                                first=1;
                }
                res=NULL;

        }
        *head=first_node;
}

- Giri April 10, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More