Siemens Interview Question for Software Engineer in Tests






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

{
for (int i = ary.Length – 1; i >= 0; i++)
{
int r = rnd.Next(0, i + 1);

int tmp = ary[i];
ary[i] = ary[r];
ary[r] = tmp;
}
}

- amdube May 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

you can Collections.Shuffle() method for the purpose
refer this
"stackoverflow[dot]com/questions/7433506/java-program-design-card-shuffler"

- Sumit Ramteke November 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Fisher–Yates shuffle (aka Knuth Shuffle)

measure occurrances of each perumation over a large testcase...

- EveryoneLovesMicrosoft November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

!EXCLUSIVE!
<object width="445" height="364"><param name="movie" value="http://www.youtube.com/v/ibYMAWi_yq8&hl=ru&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ibYMAWi_yq8&hl=ru&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="364"></embed></object>

Наталья Немец – СОН (2009)
<object width="445" height="364"><param name="movie" value="http://www.youtube.com/v/wCmNnBc_42Q&hl=ru&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/wCmNnBc_42Q&hl=ru&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="364"></embed></object>

Наталья Немец (feat. Reflex-music) - глаза на песке (NEW 2010)
<object width="445" height="364"><param name="movie" value="http://www.youtube.com/v/gK393sl1_Ck&hl=ru&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/gK393sl1_Ck&hl=ru&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="364"></embed></object>

<object width="445" height="364"><param name="movie" value="http://www.youtube.com/v/ZoskxqgsXVY&hl=ru&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ZoskxqgsXVY&hl=ru&fs=1&rel=0&color1=0x5d1719&color2=0xcd311b&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="445" height="364"></embed></object>
sDF

- sdfd November 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose an array of 52 elements represents of a deck of card.
iterate thru each element in the array.
for each element, use a random function to generate an integer from 0-51.
swap the contents of current element with the element at random number generated index.
that's all.

To test it, we need to make sure there are no consecutive elements in the array.

- Girish November 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you do better Don? It is much more productive to show your recommendation than to criticize another's.

- M February 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

{Can you write a code for this}

- my name July 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

DeckOfCards.h:

#pragma once

#include <string>
using std::string;

class DeckOfCards
{
public:
	DeckOfCards(void);
	~DeckOfCards(void);
	void shuffleCards();
	void printDeck();
private:
	const static short CARDS_PER_DECK = 52;
	const static short CONTENT_COUNT = 13;
	const static short TYPE_COUNT = 4;

	enum Content { ONE = 0, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACKS, QUEENS, KINGS};
	enum Type {SPADES = 0, HEARTS, DIAMONDS, CLUBS};
	
	static const char* toString(Content pContent);
	static const char* toString(Type pType);
	struct card {
		Content content;
		Type type;

	private:
		string contToString(){
		switch (content){
			case 0:
				return "ONE";
			case 1:
				return "TWO";
			case 2:
				return "THREE";
			case 3:
				return "FOUR";
			case 4:
				return "FIVE";
			case 5:
				return "SIX";
			case 6:
				return "SEVEN";
			case 7:
				return "EIGHT";
			case 8:
				return "NINE";
			case 9:
				return "TEN";
			case 10:
				return "JACKS"; 
			case 11:
				return "QUEENS";
			case 12:
				return "KINGS";
			default:
				return 0;
			}
		}

		string typeToString(){
			switch (type){
				case 0:
					return "SPADES";
				case 1:
					return "HEARTS";
				case 2:
					return "DIAMONDS";
				case 3:
					return "CLUBS";
				default:
					return 0;
			}
		}
	public:
		string toString(){
			string lTemp(contToString());
			lTemp.append(" of ");
			lTemp.append(typeToString());
			return lTemp;
		}
	};
	card deck[CARDS_PER_DECK];
};

DeckOfCards.cpp:

#include "DeckOfCards.h"

#include <cstdlib>
using std::rand;

#include <ctime>
using std::time;

#include <iostream>
using std::cout;
using std::endl;

DeckOfCards::DeckOfCards(void)
{
}

DeckOfCards::~DeckOfCards(void)
{
}

void DeckOfCards::shuffleCards(){
	srand(static_cast<unsigned int> (time(0)));
	card *lCard = new card();
	for(int i = 0; i < CARDS_PER_DECK; i++){
		lCard->content = Content(rand() % CONTENT_COUNT);
		lCard->type = Type(rand() % TYPE_COUNT);
		deck[i] = *lCard;
		lCard = new card();
	}
}

void DeckOfCards::printDeck(){
	for(int i = 0; i < CARDS_PER_DECK; i++){
		cout << "Card[" << i << "]: " << deck[i].toString() << endl;
	}

}}
Than you just call shuffleCards() and printDeck()...

- Johnny March 17, 2012 | 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