Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Implementing a Basic Neural Network
00:00
5 left

Implementing a Basic Neural Network

HardPython

Problem

For an Agentic AI Engineer evaluation at KMS Technology, implement a small binary classifier without using machine-learning libraries. The model must contain an input layer, one fully connected hidden layer, and one sigmoid output neuron, then train it with batch gradient descent.

Formal Specification

Implement train_neural_network(X, y, hidden_size, epochs, learning_rate), where X is a list of n feature vectors and y is a list of binary labels. Initialize all weights deterministically from their indices so repeated calls produce identical results. Use sigmoid activation in the hidden and output layers, binary cross-entropy training, and backpropagation. Return a list of predicted labels after training, using 0 for output probabilities below 0.5 and 1 otherwise.

Do not use NumPy, PyTorch, TensorFlow, or other machine-learning libraries. You may use Python's math module.

Examples

Example 1

Input: X = [[0, 0], [0, 1], [1, 0], [1, 1]], y = [0, 1, 1, 0], hidden_size = 4, epochs = 10000, learning_rate = 1.0
Output: [0, 1, 1, 0]

The hidden layer learns intermediate nonlinear features, allowing the network to represent XOR.

Example 2

Input: X = [[0], [1], [2], [3]], y = [0, 0, 1, 1], hidden_size = 3, epochs = 5000, learning_rate = 0.5
Output: [0, 0, 1, 1]

The learned output separates the lower-valued inputs from the higher-valued inputs.

Constraints

  • 1 <= n <= 200
  • 1 <= len(X[i]) <= 20
  • 2 <= hidden_size <= 20
  • 0 <= y[i] <= 1
  • 1 <= epochs <= 20000
  • 0 < learning_rate <= 2
  • All feature values are finite numbers in [-2, 2]
  • len(X) == len(y) and every feature vector has the same length

Constraints

  • 1 <= n <= 200
  • 1 <= len(X[i]) <= 20
  • 2 <= hidden_size <= 20
  • 0 <= y[i] <= 1
  • 1 <= epochs <= 20000
  • 0 < learning_rate <= 2
  • All feature values are finite numbers in [-2, 2]
  • len(X) == len(y) and all feature vectors have equal length

Function Signature

def train_neural_network(X, y, hidden_size, epochs, learning_rate):
Interviewer

Your question is Implementing a Basic Neural Network. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.