Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Tatuator handpoke

Plaja de nudisti in Grecia?

Mufa microusb a telefonului mobil...

"Ciudatenii" control pasa...
 Impamantare

Apple maps pe Windows 10

Sfarsitul woke-ismului si al core...

Probleme fibra (internet ) rooter...
 Renovare completa + pompa de cald...

Libre Office nu vad liniile

Modalitați amuzante și ...

O disparitie de ani buni, Acces D...
 Mancarea e scumpa

Parere achiziționare BMW G20

Schimbarea bateriei moderne la VA...

Rostschreck Lidl
 

Intrebare interviu

- - - - -
  • Please log in to reply
41 replies to this topic

#19
stuiberv

stuiberv

    Active Member

  • Grup: Members
  • Posts: 1,808
  • Înscris: 10.08.2006
Vad ca mai multi spun ca nu e buna intrebarea pentru un interviu.
Vreau sa aflu si de ce si poate exemple de intrebari bune.

Dupa mine e ok intrebarea, iti poti da seama daca a scris macar un program simplu in afara de "Hello World".
In plus iti poti da seama daca isi testeaza bine codul.

Daca raspunde bine la asta poti oricand sa megi mai departe.
Daca nu raspunde bine la intrebarea asta nu are rost sa intrebi altceva...

Parerea mea.

#20
andrei_0

andrei_0

    fishy

  • Grup: Moderators
  • Posts: 3,990
  • Înscris: 15.02.2006

View PostShinji, on 1st November 2011, 22:10, said:

Eu spun doar ca la o experienta de peste 5 ani in C++, intrebarea asta m-a pus pe ganduri.
:eek: OMFG

#21
m3th0dman

m3th0dman

    Senior Member

  • Grup: Senior Members
  • Posts: 9,269
  • Înscris: 03.01.2007

View PostMosotti, on 1st November 2011, 21:58, said:

n-are absolut nici o treaba cu kikitzele limbajului, pentru ca nu e nici o kikitza :w00t:

dar daca e pe C evident ca poate sa-ti arate cit a lucrat respectivul in C si despre m3th0dman si-ar da seama ca mai deloc, altfel ar fi facut cu pointeri jmekeri
Cel mai șmecherește e cu register și goto dacă vorbim de implementare și nu de algoritm. ;)

#if HAVE_CONFIG_H
# include <config.h>
#endif

#ifdef _LIBC
# define USE_NUMBER_GROUPING
# define STDC_HEADERS
# define HAVE_LIMITS_H
#endif

#include <ctype.h>
#include <errno.h>
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif

#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <xlocale.h>
#include <bits/wordsize.h>

#ifdef USE_NUMBER_GROUPING
# include "../locale/localeinfo.h"
#endif

/* Nonzero if we are defining `strtoul' or `strtoull', operating on
   unsigned integers.  */
#ifndef UNSIGNED
# define UNSIGNED 0
# define INT LONG int
#else
# define INT unsigned LONG int
#endif

/* Determine the name.  */
#if UNSIGNED
# ifdef USE_WIDE_CHAR
#  ifdef QUAD
#   define strtol_l wcstoull_l
#  else
#   define strtol_l wcstoul_l
#  endif
# else
#  ifdef QUAD
#   define strtol_l strtoull_l
#  else
#   define strtol_l strtoul_l
#  endif
# endif
#else
# ifdef USE_WIDE_CHAR
#  ifdef QUAD
#   define strtol_l wcstoll_l
#  else
#   define strtol_l wcstol_l
#  endif
# else
#  ifdef QUAD
#   define strtol_l strtoll_l
#  else
#   define strtol_l strtol_l
#  endif
# endif
#endif

#define __strtol_l __strtol_l2(strtol_l)
#define __strtol_l2(name) __strtol_l3(name)
#define __strtol_l3(name) __##name


/* If QUAD is defined, we are defining `strtoll' or `strtoull',
   operating on `long long int's.  */
#ifdef QUAD
# define LONG long long
# define STRTOL_LONG_MIN LONG_LONG_MIN
# define STRTOL_LONG_MAX LONG_LONG_MAX
# define STRTOL_ULONG_MAX ULONG_LONG_MAX
#else
# define LONG long

# ifndef ULONG_MAX
#  define ULONG_MAX ((unsigned long int) ~(unsigned long int) 0)
# endif
# ifndef LONG_MAX
#  define LONG_MAX ((long int) (ULONG_MAX >> 1))
# endif
# define STRTOL_LONG_MIN LONG_MIN
# define STRTOL_LONG_MAX LONG_MAX
# define STRTOL_ULONG_MAX ULONG_MAX
#endif


/* We use this code for the extended locale handling where the
   function gets as an additional argument the locale which has to be
   used.  To access the values we have to redefine the _NL_CURRENT and
   _NL_CURRENT_WORD macros.  */
#undef _NL_CURRENT
#define _NL_CURRENT(category, item) \
  (current->values[_NL_ITEM_INDEX (item)].string)
#undef _NL_CURRENT_WORD
#define _NL_CURRENT_WORD(category, item) \
  ((uint32_t) current->values[_NL_ITEM_INDEX (item)].word)

#if defined _LIBC || defined HAVE_WCHAR_H
# include <wchar.h>
#endif

#ifdef USE_WIDE_CHAR
# include <wctype.h>
# define L_(Ch) L##Ch
# define UCHAR_TYPE wint_t
# define STRING_TYPE wchar_t
# define ISSPACE(Ch) __iswspace_l ((Ch), loc)
# define ISALPHA(Ch) __iswalpha_l ((Ch), loc)
# define TOUPPER(Ch) __towupper_l ((Ch), loc)
#else
# if defined _LIBC \
   || defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
#  define IN_CTYPE_DOMAIN? 1
# else
#  define IN_CTYPE_DOMAIN? isascii?
# endif
# define L_(Ch) Ch
# define UCHAR_TYPE unsigned char
# define STRING_TYPE char
# define ISSPACE(Ch) __isspace_l ((Ch), loc)
# define ISALPHA(Ch) __isalpha_l ((Ch), loc)
# define TOUPPER(Ch) __toupper_l ((Ch), loc)
#endif

#define INTERNAL(X) INTERNAL1(X)
#define INTERNAL1(X) __##X##_internal
#define WEAKNAME(X) WEAKNAME1(X)

#ifdef USE_NUMBER_GROUPING
/* This file defines a function to check for correct grouping.  */
# include "grouping.h"
#endif


/* Define tables of maximum values and remainders in order to detect
   overflow.  Do this at compile-time in order to avoid the runtime
   overhead of the division.  */
extern const unsigned long __strtol_ul_max_tab[] attribute_hidden;
extern const unsigned char __strtol_ul_rem_tab[] attribute_hidden;
#if defined(QUAD) && __WORDSIZE == 32
extern const unsigned long long __strtol_ull_max_tab[] attribute_hidden;
extern const unsigned char __strtol_ull_rem_tab[] attribute_hidden;
#endif

#define DEF(TYPE, NAME)							   \
  const TYPE NAME[] attribute_hidden =					   \
  {									   \
	F(2), F(3), F(4), F(5), F(6), F(7), F(8), F(9), F(10), 		   \
	F(11), F(12), F(13), F(14), F(15), F(16), F(17), F(18), F(19), F(20),  \
	F(21), F(22), F(23), F(24), F(25), F(26), F(27), F(28), F(29), F(30),  \
	F(31), F(32), F(33), F(34), F(35), F(36)				   \
  }

#if !UNSIGNED && !defined (USE_WIDE_CHAR) && !defined (QUAD)
# define F(X)	ULONG_MAX / X
  DEF (unsigned long, __strtol_ul_max_tab);
# undef F
# define F(X)	ULONG_MAX % X
  DEF (unsigned char, __strtol_ul_rem_tab);
# undef F
#endif
#if !UNSIGNED && !defined (USE_WIDE_CHAR) && defined (QUAD) \
	&& __WORDSIZE == 32
# define F(X)	ULONG_LONG_MAX / X
  DEF (unsigned long long, __strtol_ull_max_tab);
# undef F
# define F(X)	ULONG_LONG_MAX % X
  DEF (unsigned char, __strtol_ull_rem_tab);
# undef F
#endif
#undef DEF

/* Define some more readable aliases for these arrays which correspond
   to how they'll be used in the function below.  */
#define jmax_tab	__strtol_ul_max_tab
#if defined(QUAD) && __WORDSIZE == 32
# define cutoff_tab	__strtol_ull_max_tab
# define cutlim_tab	__strtol_ull_rem_tab
#else
# define cutoff_tab	__strtol_ul_max_tab
# define cutlim_tab	__strtol_ul_rem_tab
#endif


/* Convert NPTR to an `unsigned long int' or `long int' in base BASE.
   If BASE is 0 the base is determined by the presence of a leading
   zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal.
   If BASE is < 2 or > 36, it is reset to 10.
   If ENDPTR is not NULL, a pointer to the character after the last
   one converted is stored in *ENDPTR.  */

INT
INTERNAL (__strtol_l) (nptr, endptr, base, group, loc)
	 const STRING_TYPE *nptr;
	 STRING_TYPE **endptr;
	 int base;
	 int group;
	 __locale_t loc;
{
  int negative;
  register unsigned LONG int cutoff;
  register unsigned int cutlim;
  register unsigned LONG int i;
  register const STRING_TYPE *s;
  register UCHAR_TYPE c;
  const STRING_TYPE *save, *end;
  int overflow;
#ifndef USE_WIDE_CHAR
  size_t cnt;
#endif

#ifdef USE_NUMBER_GROUPING
  struct __locale_data *current = loc->__locales[LC_NUMERIC];
  /* The thousands character of the current locale.  */
# ifdef USE_WIDE_CHAR
  wchar_t thousands = L'\0';
# else
  const char *thousands = NULL;
  size_t thousands_len = 0;
# endif
  /* The numeric grouping specification of the current locale,
	 in the format described in <locale.h>.  */
  const char *grouping;

  if (__builtin_expect (group, 0))
	{
	  grouping = _NL_CURRENT (LC_NUMERIC, GROUPING);
	  if (*grouping <= 0 || *grouping == CHAR_MAX)
	grouping = NULL;
	  else
	{
	  /* Figure out the thousands separator character.  */
# ifdef USE_WIDE_CHAR
#  ifdef _LIBC
	  thousands = _NL_CURRENT_WORD (LC_NUMERIC,
					_NL_NUMERIC_THOUSANDS_SEP_WC);
#  endif
	  if (thousands == L'\0')
		grouping = NULL;
# else
#  ifdef _LIBC
	  thousands = _NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
#  endif
	  if (*thousands == '\0')
		{
		  thousands = NULL;
		  grouping = NULL;
		}
# endif
	}
	}
  else
	grouping = NULL;
#endif

  if (base < 0 || base == 1 || base > 36)
	{
	  __set_errno (EINVAL);
	  return 0;
	}

  save = s = nptr;

  /* Skip white space.  */
  while (ISSPACE (*s))
	++s;
  if (__builtin_expect (*s == L_('\0'), 0))
	goto noconv;

  /* Check for a sign.  */
  negative = 0;
  if (*s == L_('-'))
	{
	  negative = 1;
	  ++s;
	}
  else if (*s == L_('+'))
	++s;

  /* Recognize number prefix and if BASE is zero, figure it out ourselves.  */
  if (*s == L_('0'))
	{
	  if ((base == 0 || base == 16) && TOUPPER (s[1]) == L_('X'))
	{
	  s += 2;
	  base = 16;
	}
	  else if (base == 0)
	base = 8;
	}
  else if (base == 0)
	base = 10;

  /* Save the pointer so we can check later if anything happened.  */
  save = s;

#ifdef USE_NUMBER_GROUPING
  if (base != 10)
	grouping = NULL;

  if (__builtin_expect (grouping != NULL, 0))
	{
# ifndef USE_WIDE_CHAR
	  thousands_len = strlen (thousands);
# endif

	  /* Find the end of the digit string and check its grouping.  */
	  end = s;
	  if (
# ifdef USE_WIDE_CHAR
	  *s != thousands
# else
	  ({ for (cnt = 0; cnt < thousands_len; ++cnt)
		   if (thousands[cnt] != end[cnt])
		 break;
		 cnt < thousands_len; })
# endif
	  )
	{
	  for (c = *end; c != L_('\0'); c = *++end)
		if (((STRING_TYPE) c < L_('0') || (STRING_TYPE) c > L_('9'))
# ifdef USE_WIDE_CHAR
		&& (wchar_t) c != thousands
# else
		&& ({ for (cnt = 0; cnt < thousands_len; ++cnt)
			  if (thousands[cnt] != end[cnt])
			break;
			  cnt < thousands_len; })
# endif
		&& (!ISALPHA ?
			|| (int) (TOUPPER ? - L_('A') + 10) >= base))
		  break;

# ifdef USE_WIDE_CHAR
	  end = __correctly_grouped_prefixwc (s, end, thousands, grouping);
# else
	  end = __correctly_grouped_prefixmb (s, end, thousands, grouping);
# endif
	}
	}
  else
#endif
	end = NULL;

  /* Avoid runtime division; lookup cutoff and limit.  */
  cutoff = cutoff_tab[base - 2];
  cutlim = cutlim_tab[base - 2];

  overflow = 0;
  i = 0;
  c = *s;
  if (sizeof (long int) != sizeof (LONG int))
	{
	  unsigned long int j = 0;
	  unsigned long int jmax = jmax_tab[base - 2];

	  for (;c != L_('\0'); c = *++s)
	{
	  if (s == end)
		break;
	  if (c >= L_('0') && c <= L_('9'))
		c -= L_('0');
#ifdef USE_NUMBER_GROUPING
# ifdef USE_WIDE_CHAR
	  else if (grouping && (wchar_t) c == thousands)
		continue;
# else
	  else if (thousands_len)
		{
		  for (cnt = 0; cnt < thousands_len; ++cnt)
		if (thousands[cnt] != s[cnt])
		  break;
		  if (cnt == thousands_len)
		{
		  s += thousands_len - 1;
		  continue;
		}
		  if (ISALPHA ?)
		c = TOUPPER ? - L_('A') + 10;
		  else
		break;
		}
# endif
#endif
	  else if (ISALPHA ?)
		c = TOUPPER ? - L_('A') + 10;
	  else
		break;
	  if ((int) c >= base)
		break;
	  /* Note that we never can have an overflow.  */
	  else if (j >= jmax)
		{
		  /* We have an overflow.  Now use the long representation.  */
		  i = (unsigned LONG int) j;
		  goto use_long;
		}
	  else
		j = j * (unsigned long int) base + c;
	}

	  i = (unsigned LONG int) j;
	}
  else
	for (;c != L_('\0'); c = *++s)
	  {
	if (s == end)
	  break;
	if (c >= L_('0') && c <= L_('9'))
	  c -= L_('0');
#ifdef USE_NUMBER_GROUPING
# ifdef USE_WIDE_CHAR
	else if (grouping && (wchar_t) c == thousands)
	  continue;
# else
	else if (thousands_len)
	  {
		for (cnt = 0; cnt < thousands_len; ++cnt)
		  if (thousands[cnt] != s[cnt])
		break;
		if (cnt == thousands_len)
		  {
		s += thousands_len - 1;
		continue;
		  }
		if (ISALPHA ?)
		  c = TOUPPER ? - L_('A') + 10;
		else
		  break;
	  }
# endif
#endif
	else if (ISALPHA ?)
	  c = TOUPPER ? - L_('A') + 10;
	else
	  break;
	if ((int) c >= base)
	  break;
	/* Check for overflow.  */
	if (i > cutoff || (i == cutoff && c > cutlim))
	  overflow = 1;
	else
	  {
	  use_long:
		i *= (unsigned LONG int) base;
		i += c;
	  }
	  }

  /* Check if anything actually happened.  */
  if (s == save)
	goto noconv;

  /* Store in ENDPTR the address of one character
	 past the last character we converted.  */
  if (endptr != NULL)
	*endptr = (STRING_TYPE *) s;

#if !UNSIGNED
  /* Check for a value that is within the range of
	 `unsigned LONG int', but outside the range of `LONG int'.  */
  if (overflow == 0
	  && i > (negative
		  ? -((unsigned LONG int) (STRTOL_LONG_MIN + 1)) + 1
		  : (unsigned LONG int) STRTOL_LONG_MAX))
	overflow = 1;
#endif

  if (__builtin_expect (overflow, 0))
	{
	  __set_errno (ERANGE);
#if UNSIGNED
	  return STRTOL_ULONG_MAX;
#else
	  return negative ? STRTOL_LONG_MIN : STRTOL_LONG_MAX;
#endif
	}

  /* Return the result of the appropriate sign.  */
  return negative ? -i : i;

noconv:
  /* We must handle a special case here: the base is 0 or 16 and the
	 first two characters are '0' and 'x', but the rest are no
	 hexadecimal digits.  This is no error case.  We return 0 and
	 ENDPTR points to the `x`.  */
  if (endptr != NULL)
	{
	  if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X')
	  && save[-2] == L_('0'))
	*endptr = (STRING_TYPE *) &save[-1];
	  else
	/*  There was no number to convert.  */
	*endptr = (STRING_TYPE *) nptr;
	}

  return 0L;
}
#if defined _LIBC && !defined USE_WIDE_CHAR
libc_hidden_def (INTERNAL (__strtol_l))
#endif

/* External user entry point.  */

#if _LIBC - 0 == 0
# undef PARAMS
# if defined (__STDC__) && __STDC__
#  define PARAMS(Args) Args
# else
#  define PARAMS(Args) ()
# endif

/* Prototype.  */
extern INT __strtol_l PARAMS ((const STRING_TYPE *nptr, STRING_TYPE **endptr,
				   int base));
#endif


INT
#ifdef weak_function
weak_function
#endif
__strtol_l (nptr, endptr, base, loc)
	 const STRING_TYPE *nptr;
	 STRING_TYPE **endptr;
	 int base;
	 __locale_t loc;
{
  return INTERNAL (__strtol_l) (nptr, endptr, base, 0, loc);
}
libc_hidden_def (__strtol_l)
weak_alias (__strtol_l, strtol_l)


Dar s-au ocupat băieții de la GNU de asta...

Edited by m3th0dman, 01 November 2011 - 22:55.


#22
dani.user

dani.user

    Guru Member

  • Grup: Senior Members
  • Posts: 30,255
  • Înscris: 24.02.2007

View Postandrei_0, on 1st November 2011, 22:45, said:

:eek: OMFG

+1

#23
msmihai

msmihai

    Senior Member

  • Grup: Senior Members
  • Posts: 5,271
  • Înscris: 02.09.2006
Asta e program de liceu. MAXIM.

#24
Mosotti

Mosotti

    Geniu umil

  • Grup: Senior Members
  • Posts: 33,295
  • Înscris: 21.04.2004
io pun pariu ca cel 95% din absolventii oricarei facultati din tara asta nu fac problema asta. de liceu :w00t:

#25
msmihai

msmihai

    Senior Member

  • Grup: Senior Members
  • Posts: 5,271
  • Înscris: 02.09.2006

View PostMosotti, on 1st November 2011, 23:08, said:

io pun pariu ca cel 95% din absolventii oricarei facultati din tara asta nu fac problema asta. de liceu :w00t:

normal.. is multe facultati in tara asta si nu prea cred ca unul de la arte sau de la filozofie stie programare..

#26
catalinmacovei88

catalinmacovei88

    Member

  • Grup: Members
  • Posts: 903
  • Înscris: 30.07.2011
Este o intrebare PERFECTA de interviu, sa vada cum gandesti, ce solutie, cat de rapid...si nu cum scrii cod. Notiunile de sintaxa nu ii intereseaza pe astia de la firma. Ca stii ce face functia strlen() ii doare fix in .... Si asa cum e asta program de liceu sau mai stiu eu ce...de genu se dau si pe la Microsoft, Google...

#27
Mosotti

Mosotti

    Geniu umil

  • Grup: Senior Members
  • Posts: 33,295
  • Înscris: 21.04.2004

View Postmsmihai, on 1st November 2011, 23:13, said:

normal.. is multe facultati in tara asta si nu prea cred ca unul de la arte sau de la filozofie stie programare..
...facultate de info, automatica, etc etc... arte :lol:

du-te la tine in firma, taie accesu la net si da asta la colegi. apoi posteaza rezultatele ;)

#28
m3th0dman

m3th0dman

    Senior Member

  • Grup: Senior Members
  • Posts: 9,269
  • Înscris: 03.01.2007

View Postyonut_a, on 1st November 2011, 21:57, said:

Secventa de cod scrisa mai sus nu are nicio legatura cu limbajul.Daca stiai cum, chiar nu conta in ce scriai ca era fix acelasi lucru si in C si in C++ si in Java etc...
Nu chiar; în alte limbaje (precum Java și chiar C++) String nu e chiar totuna cu array de char. Acolo fără a folosi metode predefinite nu prea văd cum ai putea...

View PostMosotti, on 1st November 2011, 23:08, said:

io pun pariu ca cel 95% din absolventii oricarei facultati din tara asta nu fac problema asta. de liceu :w00t:
De ce; ce-i greu?
N-a zis că vrea o soluție optimă.

View Poststuiberv, on 1st November 2011, 22:40, said:

[...] si poate exemple de intrebari bune. [...]
Din ceva carte de Interview Questions, de la secțiunea hard:
20.1 Write a function that adds two numbers. You should not use + or any arithmetic operators.

20.2 Write a method to shuffle a deck of cards. It must be a perfect shuffle - in other words, each 52! permutations of the 
deck has to be equally likely. Assume that you are given a random number generator which is perfect.

20.3 Write a method to randomly generate a set of m integers from an array of size n. Each element must have equal probability of being chosen.

20.4 Write a method to count the number of 2s between 0 and n.

20.5 You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between 
them in the file. Can you make the searching operation in O(1) time? What about the space complexity for your solution?

20.6 Describe an algorithm to find the largest 1 million numbers in 1 billion numbers. Assume that the computer memory can hold all one billion numbers.

20.7 Write a program to find the longest word made of other words in a list of words.
EXAMPLE
Input: test, tester, testertest, testing, testingtester
Output: testingtester

20.8 Given a string s and an array of smaller strings T, design a method to search s for each small string in T.

20.9 Numbers are randomly generated and passed to a method. Write a program to find and maintain the median value as new values are generated.

20.10 Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing 
only one letter at a time. The new word you get in each step must be in the dictionary.
EXAMPLE
Chapter 20 | Hard
92
CareerCup.com
Input: DAMP, LIKE
Output: DAMP -> LAMP -> LIMP -> LIME -> LIKE

20.11 Imagine you have a square matrix, where each cell is filled with either black or white. Design an algorithm to find the 
maximum subsquare such that all four borders are filled with black pixels.

20.12 Given an NxN matrix of positive and negative integers, write code to find the sub-matrix with the largest possible sum.

20.13 Given a dictionary of millions of words, give an algorithm to find the largest possible rectangle of letters such that every 
row forms a word (reading left to right) and every column forms a word (reading top to bottom).


Edited by dani.user, 01 November 2011 - 23:39.


#29
GigiMaciuca

GigiMaciuca

    Member

  • Grup: Members
  • Posts: 940
  • Înscris: 27.01.2010

View Postm3th0dman, on 1st November 2011, 23:34, said:

De ce; ce-i greu?
N-a zis că vrea o soluție optimă.
Ca tre' sa stii cum merge treaba cu char-ul si cu int-ul, care e ultima problema la care te gandesti cand ai ca tema/subiect de examen un sf gen sa scrii intr-un fisier o lista de studenti sortata dupa naiba-stie-ce, eventual folosind naiba stie ce algoritm de sortare.

#30
Shinji

Shinji

    Member

  • Grup: Members
  • Posts: 386
  • Înscris: 04.04.2005

View Postandrei_0, on 1st November 2011, 22:45, said:

:eek: OMFG
Mda, aroganta e boala grea... Si duce in general la a avea nasul infipt in dos, ceea ce genereaza  inabilitatea de a vedea ceva din lumea din jur, in afara de propria persoana. Asa cum s-a spus 90% din absolventii unei facultati de profil IT nu vor rezolva problema asta. De asemenea 50% din programatorii profesionisti nu se vor descurca la ea. Evident fara acces la net si cu un timp de maxim 30 de minute.

Edited by Shinji, 02 November 2011 - 00:02.


#31
Gady_paul

Gady_paul

    Senior Member

  • Grup: Senior Members
  • Posts: 2,421
  • Înscris: 12.01.2008
@m3th0dman Poti spune ce carte e aceea din care ai luat citatul?

Edited by Gady_paul, 02 November 2011 - 00:15.


#32
dani.user

dani.user

    Guru Member

  • Grup: Senior Members
  • Posts: 30,255
  • Înscris: 24.02.2007
Ce ai lucrat 5 ani in C++ daca o simpla transformare din sir de caractere in numar ti se pare grea?
Faptul ca multi trec prin facultate ca prin branza nu creste gradul de dificultate al intrebarii.

#33
Shinji

Shinji

    Member

  • Grup: Members
  • Posts: 386
  • Înscris: 04.04.2005

View Postdani.user, on 2nd November 2011, 00:12, said:

Ce ai lucrat 5 ani in C++ daca o simpla transformare din sir de caractere in numar ti se pare grea?
N-am spus ca mi se pare grea, am spus ca am avut nevoie sa ma gandesc la asta. Am avut o imagine intuitiva dar mi-a luat aproximativ 3 minute ca sa gandesc si sa scriu o solutie. Cei 5 ani de C+++ imi spun sa folosesc o functie prestabilita gen atoi. Cand ajungi sa scrii tu insuti conversia iti asumi destule riscuri, de remarcat de exemplu ca nici una din solutiile postate nu lua in considerare semnul sau caracterele eronate si sunt sigur ca sunt si alte scapari.

#34
stuiberv

stuiberv

    Active Member

  • Grup: Members
  • Posts: 1,808
  • Înscris: 10.08.2006
Ok, am vazut si exemple de intrebari bune :).


Sunt curios cati reusesc sa raspunda intr-o ora (eu nu as raspunde decat la cateva cred - in sensul ca as putea sa gasesc un algoritm - nu m-am uitat la toate).

De xemplu asta: Write a function that adds two numbers. You should not use + or any arithmetic operators.
Ma gandesc la operatii pe biti, dar sincer ar trebui sa iau hartia si creionul, sa imi aduc aminte exact cum e cu reprezentarea numerelor in complement fata de 2, sa fac niste adunari si apoi sa incerc sa gasesc regula care sa faca adunarile in complement fata de 2. Nu am verificat, s-ar putea sa fiu complet pe langa :D.
E adevarat, intrebarea asta ar elimina pe oricine care nici macar nu a auzit de operatii pe biti si de reprezentarea numerelor in binar...



Dupa mine e mai bine sa incepi cu o intrebare normala (poate chiar usoara) ca sa ai de unde pleca.

Daca pui direct o intrebare grea, poate nu iti va raspunde, dar poate ar raspunde foarte bine la intrebarile usoare si medii.


Acum, depinde si ce nivel are candidatul, dar asta o poti afla doar dupa ce il intrebi cate ceva, chiar daca sa spunem ca are experienta trecuta in CV.

In plus, daca ii pui direct o intrebare grea nu iti poti da seama de prea multe daca nu raspunde.

Inca o chestie: daca ii pui o intrebare mai usoara si reuseste pana la urma sa o rezolve, chiar daca nu il angajezi, pleaca de la interviu cu o impresie buna si poate mai incearca sa invete - ca sa nu mai spunem ca poate le spune si unor coleg/prieteni sa vina la interviu - si s-ar putea ca unul din ei sa raspunda la toate intrebarile :).

Ce vroiam sa spun: nu trebuie sa spui ca nu e o intrebare buna pentru ca e usoara.
Ideea unei intrebari e sa il vezi cum gandeste si apoi sa scrie codul, sa vezi cum il testeaza.

La atoi eu cred ca sunt destule de avut in vedere (ca si la alte intrebari simple/medii).

Daca trece fluierand prin prima intrebare, poti continua pana unde vrei tu.
Daca la prima e la pamant, nu are rost sa te mai complici.

#35
m3th0dman

m3th0dman

    Senior Member

  • Grup: Senior Members
  • Posts: 9,269
  • Înscris: 03.01.2007

View PostGigiMaciuca, on 1st November 2011, 23:42, said:

Ca tre' sa stii cum merge treaba cu char-ul si cu int-ul, care e ultima problema la care te gandesti cand ai ca tema/subiect de examen un sf gen sa scrii intr-un fisier o lista de studenti sortata dupa naiba-stie-ce, eventual folosind naiba stie ce algoritm de sortare.
Da' astea-s chestii oarecum elementare; sau cel puțin ar trebui să le revizuiești bine înainte de a te duce la un interviu.

View PostGady_paul, on 2nd November 2011, 00:12, said:

@m3th0dman Poti spune ce carte e aceea din care ai luat citatul?
Da.
Cracking The Coding Interview, Gayle Laakmaan, CareerCup, LLC.

View Poststuiberv, on 2nd November 2011, 10:26, said:

1. De xemplu asta: Write a function that adds two numbers. You should not use + or any arithmetic operators.
Ma gandesc la operatii pe biti, dar sincer ar trebui sa iau hartia si creionul, sa imi aduc aminte exact cum e cu reprezentarea numerelor in complement fata de 2, sa fac niste adunari si apoi sa incerc sa gasesc regula care sa faca adunarile in complement fata de 2. Nu am verificat, s-ar putea sa fiu complet pe langa :D.


2. E adevarat, intrebarea asta ar elimina pe oricine care nici macar nu a auzit de operatii pe biti si de reprezentarea numerelor in binar...
1. Păi n-ai voie cu adunări, fie ele și-n binar; trebuie să imiți procesorul, cu XOR (și AND pentru carry out).

2. Sau poți transforma în string și să faci multe if-else:
if(a[i] == '0' && b[i] == '0') {
     s[i] = '0';
     c = '0';
}
//...
if((a[i] == '5' && b[i] == '7' ) || (a[i] == '7' && b[i] == '5') || (a[i] == '6' && b[i] == '6') || ... ) {
     s[i] = '2';
     c = '1';
}
//...
if(c == 1)
//....
s[i-1] = ...;

3. De fapt cel mai simplu de scris cred că e o combinație a celor două.

L.E.
Soluția dată de ei:  :blink:
Am descoperit că există două tipuri de shifting: arithmetic și logical. Credeam că orice bit shifting e o operație aritmetică...

int add_no_arithm(int a, int b) {
if (b == 0) return a;
int sum = a ^ b; // add without carrying
int carry = (a & b) << 1; // carry, but don?t add
return add_no_arithm(sum, carry); // recurse
}

Edited by m3th0dman, 02 November 2011 - 11:29.


#36
stuiberv

stuiberv

    Active Member

  • Grup: Members
  • Posts: 1,808
  • Înscris: 10.08.2006

View Postm3th0dman, on 2nd November 2011, 11:23, said:

1. Păi n-ai voie cu adunări, fie ele și-n binar; trebuie să imiți procesorul, cu XOR (și AND pentru carry out).

Da, iar nu am scris exact pana la capat :).

Trebuie sa gasesc o regula in care se fac adunarile in binar in sensul de manipulari de biti.
Regula asta daca nu o stii pe de rost trebuie sa faci cateva adunari si sa o observi - dupa cum ai spus XOR si AND. Nu stiu daca e foarte usor de observat, chiar am sa incerc (desi acum stiu despre ce operatii e vorba) :D.

Ca adunarea in binar tot adunare e, dupa cum ai spus.

Oricum, cu intrebarea asta m-am mai gandit dupa prima idee cu bitii si la partea cu regulile cu stringuri, acolo e "mai usor", dar trebuie sa ai grija sa acoperi toate cazurile.

Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate