instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Create a HTML page to display the top 5 scores from a given array. The array contains a mixture of positive and negative numbers. The page should display the scores in descending order, with the highest score at the top. If there are multiple scores with the same value, they should be displayed in the order they appear...
codefeedback
Develop an algorithm to traverse a two-dimensional array. A two-dimensional array with 10,000 rows and 10,000 columns.
codefeedback
Compose a regular expression to extract the first digit after the first occurrence of the character "a" in a given string. String: "abc123 456xyz"
codefeedback
Construct a function that takes in a string as input and returns a dictionary where the keys are the characters in the string and the values are the counts of each character. The function should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1).
codefeedback
Design a JavaScript class to perform a specific operation on a given matrix with the following constraints: - The matrix must have at least 2 rows and 2 columns. - The elements in the matrix must be positive integers. - The class should include a method to add a new row to the matrix. - The class should include a metho...
codefeedback
Suppose you are given an array of active processes, write an algorithm in C++ that returns the process with the highest execution time, but you are not allowed to use any built-in sorting functions or algorithms. The array of process objects will still have the properties {name, id, priority, executionTime}.
codefeedback
Design a web page to display the first ten elements of a given 2D array. A 2D array [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] You need to create a table with 10 cells to display the first ten elements of the given 2D array. Each cell should display one element from the array. The elements should be displayed in ...
codefeedback
Create a script in Python to sort a given array in descending order using only recursion. The input array will contain unique integers between 1 and 1000 inclusive.
codefeedback
Generate code in C++ to determine the number of palindromic substrings in a given string. Your solution should have a time complexity of O(n^2) and use dynamic programming.
codefeedback
Design a program to remove all occurrences of a specific punctuation mark from a given string, while preserving the positions of other punctuation marks and characters.
codefeedback
Design a data structure in C++ to store a large set of customer data, where each customer has the following attributes: name, age, email, and phone number. The data structure should support the following operations: 1. Add a new customer to the set. 2. Remove an existing customer from the set. 3. Update the informatio...
codefeedback
Design an efficient algorithm in Java for solving a linear search problem. The algorithm should have a time complexity of O(n) and should be able to handle large input sizes of up to 10^6 elements. Additionally, the algorithm should use a divide and conquer approach to improve its efficiency.
codefeedback
Design a data structure in Java to store students' marks in an examination, ensuring that each student's marks are stored in a separate object with their name and ID, and allowing for efficient searching and sorting of the marks based on different criteria. Additionally, the data structure should support updating and d...
codefeedback
How can a class be extended in Java while ensuring that the derived class must override a specific method from the base class?
codefeedback
Write HTML code for a form that contains a text input field with the following requirements: 1. The input field should have a placeholder that says "Enter name". 2. The input field should have a maximum length of 20 characters. 3. The form should have a submit button that is disabled by default. 4. The submit button sh...
codefeedback
Write a SQL query to get the names, job titles, and salaries of all the employees in the "sales" department who have a salary higher than $55,000. Additionally, the query should sort the results in descending order of the employee's hire date and should only consider employees who have been with the company for more th...
codefeedback
Formulate a query in MongoDB to find records with a specific field having an array containing a certain value. Additionally, the query should only return documents where the array contains the value more than once.
codefeedback
Develop JavaScript code to find the nth Fibonacci number within a time complexity of O(log n).
codefeedback
Develop a Python program to calculate the area of a triangle given its three sides. The program should also verify if the given sides form a valid triangle by checking if the sum of any two sides is greater than the third side. If the sides do not form a valid triangle, the program should display an error message. Addi...
codefeedback
Write a Lambda function in Python to generate random numbers in the range of 10 to 50. The generated numbers should be unique and stored in a list. Additionally, the function should return the sum of all the generated numbers.
codefeedback
Write an objective-C program to print the number of prime numbers in an integer.
codefeedback
Write a compare() function in Java that takes two values and returns -1, 0, or 1 if the first value is less than, equal to, or greater than the second value. However, you are not allowed to use any comparison operators (such as <, >, ==) or arithmetic operators (such as +, -, *, /) in your implementation.
codefeedback
Rewrite the following code to use more efficient loops while ensuring that the output is only "hi" if the sum of i and j is an odd number.
codefeedback
Create a query in MySQL to list the number of male and female employees in a given department. However, the gender column in the employees table is stored as integers, with 1 representing male and 2 representing female. Additionally, the department column is stored as a comma-separated string, with multiple departments...
codefeedback
Write a script in JavaScript to calculate the average temperature from a given array of temperatures, but exclude any temperatures below 0 degrees Celsius.
codefeedback
How would you fill in the blanks in the following code to make it print "Hello, World" n times in a row, where n is a positive integer? n = 5 for _ in range(n): _______________
codefeedback
Train a convolutional neural network using TensorFlow to predict housing prices based on images of the houses.
codefeedback
Make the following C++ program print "Hello, World" 10 times consecutively, but without using any loop or recursion. #include<iostream> int main() { ________ return 0; }
codefeedback
Create a web page with a navigation bar at the top that includes dropdown menus and submenus.
codefeedback
Create a PyTorch implementation of a neural network with the following structure: Input shape: (300, 100) Hidden layer 1: 200 neurons, followed by a ReLU activation function Hidden layer 2: 150 neurons, followed by a ReLU activation function Output layer: (2, 5), followed by a softmax activation function Ensure that ...
codefeedback
Change the line in the following code that contains a syntax error. Additionally, modify the code to only print the statement 'x is 10' if the variable 'x' is less than or equal to
codefeedback
Create a Python program to generate a random 8-character alphanumeric string. The string should contain at least one lowercase letter, one uppercase letter, one digit, one special character, and must also satisfy the additional constraint of having exactly two lowercase letters, two uppercase letters, two digits, and t...
codefeedback
Write a loop that prints the numbers from 0 to 9 on the console in reverse order.
codefeedback
Create a Python program to convert an input string to Morse code, with the following additional requirements: 1. The program should validate the input string and ensure that it only contains valid characters. If any invalid characters are found, the program should display an error message and terminate. 2. The program...
codefeedback
Create a regex to extract all the names (first name and last name) from a string "John Doe is a programmer and Jane Smith is a doctor". "John Doe is a programmer and Jane Smith is a doctor"
codefeedback
Construct a SQL query to retrieve the top 10 most viewed articles from the database, excluding articles that have been viewed less than 100 times and have a content length of less than 500 characters. Table "articles": - id (integer) - title (string) - content (string) - views (integer) - published_date (date) - author...
codefeedback
Create a React component to display a large dataset of HTML elements in a scrolling page with lazy loading. The component should have the following requirements: 1. Accept a `data` prop which is an array of HTML elements to be displayed. 2. Display only a portion of the data initially, enough to fill the visible area...
codefeedback
Implement a closure in programming and provide a practical use case for it.
codefeedback
Create a method to multiply two matrices.
codefeedback
Write a function to generate a random password that is 10 characters long and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character.
codefeedback
Read the input values and sort them in ascending order. The input values consist of both integers and strings. The sorting should be done in such a way that the integers are sorted first in ascending order, followed by the strings in lexicographic order. If there are multiple integers or multiple strings with the same ...
codefeedback
Write a Python expression to compute the exponential of a given number, but you are not allowed to use any built-in functions or modules related to exponentiation or mathematical calculations. You can only use basic arithmetic operations and loops. x = 3
codefeedback
Create an algorithm that prints the common elements of two arrays. The algorithm should have a time complexity of O(n+m), where n and m are the lengths of the two arrays. The algorithm should also have a space complexity of O(min(n, m)), meaning it should use additional space proportional to the length of the smaller a...
codefeedback
Implement the quicksort algorithm to sort an array of integers in ascending order. Erroneous code reference: ```python def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[0] left = [x for x in arr[1:] if x <= pivot] right = [x for x in arr[1:] if x > pivot] return quicksort(left) +...
codefeedback
Write a Python program that truncates a given string after a specified number of characters. The program should display the truncated string with ellipsis (...) at the end if the string is longer than the specified limit. If the limit is less than or equal to 0, the program should display an error message. Example: I...
codefeedback
Write a piece of code in Python that prints a multiplication table from 1 to 10. The table should include both the multiplicand and the multiplier, and display the product for each pair. The table should be formatted in a neat and visually appealing way, using appropriate spacing and alignment.
codefeedback
Create a HTML page that contains the following text: "Welcome to my website!" and also include a CSS file that styles the text with a unique font, color, and size.
codefeedback
Construct a Python dictionary with the countries and their total population. The countries list contains duplicate values, which should be handled appropriately. Additionally, the population values should be provided in descending order.
codefeedback
Write a code to encrypt a text using a Vigenère cipher
codefeedback
Modify the code below to print the 10th and 11th prime numbers in ascending order. ```python def is_prime(n): if n <= 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def get_primes(n): primes = [] num = 2 while len(prime...
codefeedback
Create a program to convert a string of binary characters to its equivalent hexadecimal value String: 11001010
codefeedback
Determine whether a given string contains a valid number that is at least 3 characters long and consists of only digits and alphabetic characters. The number should start with a letter and end with a digit. String: abc123
codefeedback
Sum the integers from 0 to 100 and display the result.
codefeedback
Parses the following JSON object and create an object from it. The "name" field should be a string consisting of only alphabetic characters, the "age" field should be a positive integer, and the "address" field should be a string consisting of alphanumeric characters only, with a maximum length of 50 characters.
codefeedback
Rewritten Test: Implement a function in Python that can remove a specified element from a tuple without using built-in functions or libraries. Input: - A tuple of integers or strings - A target element to be removed Output: - A new tuple with the specified element removed Example: Input: - tuple: (1, 2, 3, 4, 5) - e...
codefeedback
Modify the given code to multiply each element in the list by 5, but only if the element is a prime number. lista = [3, 4, 6, 7]
codefeedback
You are given a nearly sorted array and need to determine the best sorting algorithm to use in this scenario. Provide a detailed explanation for your choice, considering factors such as time complexity, space complexity, and any trade-offs associated with different sorting algorithms.
codefeedback
Swap the two variables without using a temporary variable and only using a maximum of 2 assignment statements. a = 3 b = 7
codefeedback
Create a program to generate the Pascal's triangle up to a given row number, where the row number is a prime number.
codefeedback
Design a GUI using JavaScript for a calculator application that supports basic arithmetic operations (+, -, *, /) as well as advanced functions such as square root, exponentiation, and trigonometric functions. The calculator should also have a memory feature that allows users to store and recall previous calculations. ...
codefeedback
Using classes, create an object that can describe a geometric shape. The object should be able to calculate the area and perimeter of the shape. Additionally, it should be able to check if a given point is inside the shape. The geometric shape can be either a rectangle or a circle.
codefeedback
Given a dictionary with keys as strings and values as numbers, calculate the sum of the values. If a key contains any uppercase letters, ignore that key and do not include its corresponding value in the sum. myDict = {'x': 12, 'y': 23, 'Z': 8, 'a': 10} Expected Output: 45
codefeedback
Write a function to rearrange a given string in alphabetical order, considering both uppercase and lowercase letters. The function should also remove any duplicate characters from the string. The rearranged string should be returned. Example: Input: "Hello World" Output: " deHlorw" To solve this problem, you can foll...
codefeedback
Generate an array that contains the first n odd Fibonacci numbers greater than 1000. n = 10
codefeedback
Given a binary number as a string, convert it to a hexadecimal number and return it as a string. Example: Input: "1011" Output: "B" Note: The input binary number will always be a valid binary number and the output hexadecimal number should be in uppercase.
codefeedback
Find all the prime factors of N (greater than 1), add them together and return the result. N must be a positive integer greater than 1.
codefeedback
Write a SQL query that retrieves the owner's id, name, and address of a specific car, as well as the total number of cars they own and the average price of their cars. Table: cars Columns: id, car_name, owner_id, owner_name, owner_address, price Car Name: "Toyota Corolla"
codefeedback
Write code to return the kth element in the Fibonacci sequence, but with a time complexity of O(log n).
codefeedback
Explain why the Observer design pattern is useful in object-oriented programming?
codefeedback
Write a Ruby function that takes two strings, s and t, as arguments and returns true if s is a substring of t, and false otherwise. The function should also check if s is a palindrome. Additionally, the function should only consider the substring starting from the second character of t.
codefeedback
Compute the maximum sum of m consecutive values in a given array, but with the following additional constraints: 1. The array may contain negative numbers. 2. The array may be empty or contain less than m elements, in which case the maximum sum should be considered as 0. 3. If there are multiple subsequences with the s...
codefeedback
Write a Haskell code snippet to find the length of a given list without using any built-in functions or recursion.
codefeedback
Design a function in JavaScript to find the sum of the first n numbers. Additionally, the function should check if the input is a positive integer and return an error message if it is not.
codefeedback
Create a Java function to calculate the area of a triangle from its three vertices. The vertices are given as (x,y) coordinates in the Cartesian plane. The function should handle both integer and floating-point coordinates. Example Input: A=(2,3), B=(3,4), C=(4,5) Example Output: The area of the triangle formed by th...
codefeedback
Design a sorting algorithm to order a list of integers in descending order, without using any built-in sorting functions or libraries. [15,22,4,13,10,17,8]
codefeedback
Write a Python program to make a dictionary that contains a number as a key, and its cube as the corresponding value. The program should also check if the number is a prime number and only add it to the dictionary if it is a prime number.
codefeedback
Using the given array, create a JavaScript function that returns the sum of all elements in the array. The function should only iterate through the array once and must have a time complexity of O(n). Additionally, the function should not use any built-in array methods or operators such as reduce, map, or for loops. The...
codefeedback
Write a Python code that prints all the distinct longest continuous increasing sequences of integers within a given list. The input list will contain integers only, and its length will not exceed 10^6. The integers in the list will range from -10^6 to 10^6. Your code should have a time complexity of O(n), where n is ...
codefeedback
Write a function in Java that takes in a string and shifts all the characters three places to the right, wrapping around the end. #Erroneous Code Reference# x = "Hello!" x = x + 3
codefeedback
Write a function in Java to delete all occurrences of a specific item from an ArrayList. The function should have a time complexity of O(n) and a space complexity of O(1). list = [1,2,3,4,5,2,3,2]
codefeedback
Create a bash script that takes in an input file containing multiple lines, each line containing two space-separated integers. The script should calculate the sum of each pair of integers and print the output to a separate output file. Additional requirements: 1. The input file should have a maximum of 1 million lines...
codefeedback
Using list comprehension, write a Python code to get a list of all possible subsets of the list [1, 2, 3, 4] that have a sum greater than 5.
codefeedback
Implement a method to generate a random password with a length between 10 and 16 characters, which must contain at least one capital letter, one small letter, one digit, and one special character (e.g., !@#$%^&*). The password should not contain any repeating characters.
codefeedback
Implement a function that returns the total number of vowels in a string in C++. string str = "Hello World!" Provide a piece of erroneous code as a reference to increase misdirection: int countVowels(string str) { int count = 0; for (int i = 0; i < str.length(); i++) { if (str[i] == 'a' || str[i...
codefeedback
Filter the following list of integers using Python, so that only the numbers divisible by both 2 and 3 are left. Additionally, the filtered numbers should be in descending order. Original list: [1, 2, 3, 4, 5, 6, 7, 8]
codefeedback
Write a method in Java that returns an array of the first N prime numbers. n=10 **Reference Erroneous Code:** ```java public static int[] getFirstNPrimeNumbers(int n) { int[] primeNumbers = new int[n]; int count = 0; for (int i = 2; count < n; i++) { if (isPrime(i)) { primeNumbers[count...
codefeedback
Write a function to print an array without duplicate elements, but you are not allowed to use any built-in functions or data structures. The input array will contain only positive integers. Example: Input: [4,3,6,5,4,7] Output: [4,3,6,5,7]
codefeedback
Write a code that converts degrees Celsius to degrees Fahrenheit. Additionally, handle the scenario when the input value is invalid (e.g. a string or a negative number).
codefeedback
Demonstrate how to create a SQL query to get a list of all employees from the employees table, sorted in descending order by their hire date and only including employees who have been with the company for more than 5 years.
codefeedback
Write a code that finds the largest palindromic number in a given array and returns its index. If there are multiple palindromic numbers with the same maximum length, return the index of the first occurrence. If there are no palindromic numbers in the array, return -1. Example: Input: [73, 111, 109, 121, 545, 777, 22]...
codefeedback
Write a SQL query to select all records from a table named 'customers' where the city is either 'London' or 'Paris', and the customer's age is greater than 25.
codefeedback
Create a function to detect if a given string contains all lowercase letters of the English alphabet. The function should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1).
codefeedback
Train a logistic regression model using Scikit-Learn to predict the class labels of the given dataset. import numpy as np from sklearn.linear_model import LogisticRegression X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]]) Y = np.array([0, 0, 1, 1]) # Fit the logistic regression model to the training data model = ...
codefeedback
Write a JavaScript code to read the content of a given URL and store it in a database. #Explanation# In the given test, the code only needs to read the content of a URL. In the rewritten test, the code also needs to store the content in a database. This adds complexity as it requires additional database handling and s...
codefeedback
Generate a correct SQL query to select the three highest-priced products in a product table, considering the following additional conditions: - Exclude any products that are out of stock. - Calculate the average price of all products in the table. - Retrieve the name, price, and quantity of the three highest-priced pro...
codefeedback
Create a function in Python that takes a string as input and returns a dictionary containing the frequency of characters in the string. The function should handle both uppercase and lowercase characters as separate entities. Additionally, the function should ignore any special characters or punctuation marks in the inp...
codefeedback
Identify and correct the error in this C++ code. The corrected code should also include a function that calculates the sum of all even numbers from 1 to n (inclusive), where n is a user-inputted positive integer. The sum should be displayed after the program prints either "1" or "2".
codefeedback
Create a NumPy array to store the values of a given function within a specified range of x values, with a step size of 0.5. The array should only include values that are greater than 0. Also, the function should only be applied to x values that are multiples of 3. Finally, the resulting array should be sorted in descen...
codefeedback
Write a JavaScript program to sort an array of strings according to the length of each string. The program should also handle strings that contain both uppercase and lowercase letters. Additionally, the program should ignore any strings that contain numbers or special characters. Finally, the program should sort the st...
codefeedback
Develop a logistic regression model using Python to predict the outcome of a binary classification dataset, but with the additional requirement that the model must handle imbalanced classes by implementing a suitable method such as oversampling or undersampling.
codefeedback