instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
In JavaScript, construct a function to count the occurrence of an element in an array, but the array can contain nested arrays as well. The function should recursively search for the element in the array and its nested arrays. Additionally, the function should return the count of occurrences as well as the indices at w...
codefeedback
Write a SQL query to get all employees' name, salary, and years of experience who are from the department "IT" and have a salary above the average salary of all employees in the company.
codefeedback
Convert the following SQL query into a Java code using JDBC. SELECT Employees.Name, Departments.DepartmentName FROM Employees JOIN Departments ON Employees.DepartmentID = Departments.ID WHERE Employees.Salary > 50000 AND Departments.Location = 'New York' ORDER BY Employees.Name ASC LIMIT 10
codefeedback
Suggest an API endpoint in Ruby on Rails for creating a new blog post with the following additional requirements: - The blog post should have a minimum word count of 500 words. - The blog post should include at least one image attachment. - The API should automatically generate a unique slug for the blog post based on ...
codefeedback
Develop a program to convert an infix expression to prefix notation. The infix expression may contain the following operators: +, -, *, /, ^ (exponentiation), and % (modulus). The operands can be positive or negative integers. For example, given the infix expression: 5 + 3 * 2 - 7, the program should output the prefix...
codefeedback
Create a Swift class that implements a queue data structure with the following methods: - `enqueue`: Adds an element to the back of the queue. - `dequeue`: Removes and returns the element at the front of the queue. - `isEmpty`: Returns a boolean value indicating whether the queue is empty. - `size`: Returns the number ...
codefeedback
Generate a dynamic HTML table displaying 1000 random numbers from 1 to 1000, sorted in descending order.
codefeedback
Construct a SQL query to get all the rows of a table ordered by the sum of all values in each row, in descending order.
codefeedback
Develop an HTML page with three sections, each containing different colors. Additionally, implement a feature that allows users to change the colors of each section by clicking on a button.
codefeedback
List all possible combinations of three distinct elements from a given array, where the sum of the elements in each combination is equal to a given target value. The array may contain duplicate elements.
codefeedback
Develop a new class in Python to represent a Rectangle object with the following methods: getArea(), getPerimeter(), and getDiagonal(). Additionally, the Rectangle object should have a validate() method that checks if the provided length and width values are valid (greater than 0). The Rectangle object should also impl...
codefeedback
Explain the process of dynamic memory allocation in C++ and discuss the advantages and disadvantages compared to static memory allocation. Provide code examples to illustrate your points.
codefeedback
Develop a class in Java to implement a calculator with functions add(), subtract(), multiply(), and divide(). Please include error handling for the following scenarios: 1. Division by zero: If the divisor is zero, throw a custom exception "DivisionByZeroException" with an appropriate error message. 2. Invalid input: I...
codefeedback
Write a C++ program that demonstrates the differences between the stack and the heap memory by implementing a custom memory management system. The system should allow dynamic allocation and deallocation of memory on both the stack and the heap, and should include the following functionalities: 1. A function to allocat...
codefeedback
Write a C++ program to implement a binary tree and store integers in it. The program should include the following functionalities: 1. Insertion of nodes in the tree. 2. Deletion of nodes from the tree. 3. Searching for a specific element in the tree. 4. Finding the height of the tree. 5. Displaying the tree in an inord...
codefeedback
Extend the program from Question 4 to allow the user to specify the upper limit and the lower limit as well. Additionally, modify the program to only calculate and display the prime numbers within the specified range.
codefeedback
Develop a function in C++ to find the roots of a cubic equation ax^3 + bx^2 + cx + d = 0.
codefeedback
Create an SQL table to store information about books, authors, and publishers. Additionally, ensure that the table has proper constraints to enforce referential integrity, such as foreign key relationships between the books and authors, as well as books and publishers.
codefeedback
Write a code that migrates data from one database to another, while also transforming and manipulating the data in the process. Additionally, the code should be optimized to handle large datasets efficiently and effectively.
codefeedback
Write a Java program to find the sum of two arrays of length 10, where each array element is a 10-digit positive integer. The program should also handle cases where the sum of the corresponding elements in the two arrays exceed the maximum value of a 10-digit integer.
codefeedback
Implement the quicksort algorithm using C++ and ensure that the time complexity is O(nlogn) and the space complexity is O(logn).
codefeedback
Write a C program to simulate the producer-consumer problem with the following constraints: 1. The program should use multithreading to simulate multiple producers and consumers. 2. Each producer should have a maximum production capacity of 10 items. 3. Each consumer should have a minimum consumption rate of 1 item pe...
codefeedback
Write a JavaScript function that takes in an array of numbers and returns a new array containing only the numbers that are greater than 10. The function should also sort the resulting array in descending order.
codefeedback
Construct a for loop in PHP that produces the Fibonacci sequence up to the 10th number.
codefeedback
Implement the insertion sort algorithm to sort a list of strings in descending order based on the length of each string.
codefeedback
Write a JavaScript function that removes duplicates from an array. The function should have a time complexity of O(n), where n is the length of the array. Additionally, the function should not use any built-in JavaScript methods for removing duplicates (such as Set or filter). array = [1, 2, 3, 1, 4, 5, 6, 2, 8]
codefeedback
Write a function to compute the nth Lucas number and the sum of their cubes, where Lucas numbers are defined as follows: L(n) = L(n-1) + L(n-2) for n > 1 L(0) = 2 L(1) = 1
codefeedback
Given a dictionary, write a function to count the number of items in the dictionary. The dictionary may contain nested dictionaries as values. You need to consider all levels of nesting and count the total number of items in the dictionary, including the nested dictionaries and their items. For example, consider the f...
codefeedback
Write a loop to print out all the elements in the given dictionary in descending order of their values, while excluding any elements with values less than or equal to 1. my_dict = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 0, "g": 6, "h": 2}
codefeedback
Create a Java program that reads in two strings and outputs their longest common substring. The program should also display the starting and ending indices of the longest common substring in each input string. Additionally, the program should consider case sensitivity when comparing the strings. For example, given the ...
codefeedback
Design and 3D print a fully functional model of a multi-story house with intricate architectural details, such as windows, doors, and a roof, while ensuring that the dimensions of each room are accurate and to scale.
codefeedback
Write a Swift program to convert a Python dictionary to a Swift dictionary. The Python dictionary contains both string and integer keys and the corresponding values are either integers or lists of integers. py_dict = {"a": 1, "b": [2, 3], "c": [4, 5, 6]}
codefeedback
Write an SQL query to create a table called "orders" with columns for the order id, customer name, order date, and order total. Additionally, the order id should be the primary key and the customer name should be unique.
codefeedback
Create a class to store data of a patient's medical record. The medical record should include the following information: - Patient's name (string) - Patient's date of birth (string) - Patient's gender (string) - Patient's blood type (string) - Patient's height in centimeters (float) - Patient's weight in kilograms (fl...
codefeedback
Develop a web page with React that dynamically generates a word cloud based on the frequency of words in a given text file. The word cloud should also allow the user to filter out common stop words and specify the maximum number of words to be displayed.
codefeedback
Write a Swift code snippet to create a button with user specified text and size. Additionally, make the button change its color randomly every time it is tapped.
codefeedback
Write a C program to output all prime numbers from 0 to 500.
codefeedback
Create an HTML form that includes inputs for first name, last name, email address, and password. Implement validation for each input field as follows: - The first name and last name fields should not be empty and should only contain alphabetic characters. - The email address field should not be empty and should have a ...
codefeedback
Write a PHP script to check if an input is a number, a string, or an array. #Additional Instructions# 1. If the input is an array, check if all its elements are either numbers or strings. 2. If the input is a string, check if it contains any special characters or symbols. 3. If the input is a number, check if it is a ...
codefeedback
Create a function in R to determine the probability of rolling a dice with a given number of sides, considering that the dice is biased and each face has a different probability of being rolled. The probability for each face should be provided as input to the function. Additionally, the function should also take into ...
codefeedback
Write a CSS program to change the text color of a given element from red to blue. The program should also change the background color of the element from white to black. Additionally, the program should animate the transition of the text color from red to blue over a duration of 2 seconds using CSS animations. Finally,...
codefeedback
Write a JavaScript function to check if a given input number is perfect or not. A perfect number is a number whose sum of divisors (excluding the number itself) equals the number itself. #Erroneous Code# ```javascript function isPerfectNumber(num) { let sum = 0; for(let i = 1; i <= num/2; i++) { if(num % i ...
codefeedback
Write an SQL query to list all the customers who have purchased any item from the “electronics” category and have made at least 3 purchases.
codefeedback
Using a for loop, count the number of words in the below string, but ignore any occurrences of the word "test" and its variations ("testing", "tested", etc.). string = "This is a testing string and I have tested it multiple times"
codefeedback
Generate Fibonacci numbers up to 10^8 using a while loop.
codefeedback
Create a lambda function in Python to fetch the age of a person from their given DOB. The function should also handle leap years and account for time zones to accurately calculate the age.
codefeedback
Create a function that takes in a string and returns a dictionary with each word as a key and its count as the value. However, the function should also handle cases where the string may contain punctuation marks and different casing. Additionally, the function should ignore common stopwords (such as "the", "and", "is",...
codefeedback
Create a HTML page which displays the result of multiplying two user-provided numbers. However, the multiplication operation should be implemented using only bitwise operators (e.g., shift, AND, OR, XOR) and not using the multiplication operator (*). Additionally, the solution should have a time complexity of O(1) and ...
codefeedback
Create a three-dimensional array with all elements set to 0 of length 3×2×2. Additionally, initialize the array with a specific pattern where each element in the first dimension is set to its index value, each element in the second dimension is set to its index value plus 1, and each element in the third dimension is s...
codefeedback
Create a website that displays the current day's weather forecast in Philadelphia, as well as a 7-day forecast. Implement a feature that allows users to toggle between Fahrenheit and Celsius temperature units. Additionally, include a search bar that allows users to enter any location and retrieve the weather forecast f...
codefeedback
Create an SQL query to retrieve all records from a table where the values of two columns do not match and the values of a third column are greater than 100.
codefeedback
Generate a Python program to perform matrix multiplication using only bitwise operations and without using any built-in functions or libraries.
codefeedback
Write a function that parses a json string into a Python dict. Your function should handle nested objects and arrays within the json string. Additionally, it should handle different data types within the json string, such as integers, floats, and booleans.
codefeedback
Create a JavaScript program to print out a pattern of numbers in a specific format. #Updated Difficulty Level: Intermediate ## Examples: 1. For input `5`, the program should print: ``` 1 22 333 4444 55555 ``` 2. For input `3`, the program should print: ``` 1 22 333 ``` 3. For input `6`, the program should print: ``...
codefeedback
Write a C++ program to sort a given array of integers in ascending order, using the bubble sort algorithm. The array should have at least 10 elements and each element should be within the range of -100 to 100, inclusive. The program should also print the number of comparisons and swaps made during the sorting process. ...
codefeedback
Modify the given code to be able to print an asterisk pyramid as specified in the output. The program should also validate the input to ensure that the number of rows is a positive integer. Additionally, the program should prompt the user to enter the number of rows instead of using a fixed value. The output should hav...
codefeedback
Suggest a command-line program that takes a directory path as input and recursively prints the contents of all subdirectories within that directory, including their subdirectories, in a tree-like structure.
codefeedback
Explain the concept of lexical analysis and how it is used in the process of interpreting programming code. Additionally, provide an example of a specific programming language and explain how its interpreter performs lexical analysis.
codefeedback
Code a program that takes a list and removes all the duplicate numbers. The program should also sort the list in descending order and display the final result. Additionally, the program should handle cases where the input list contains non-integer elements and remove any non-numeric elements from the list before proces...
codefeedback
Write a code to create a FizzBuzz game, that prints the numbers from 1 to 100, replacing all the numbers divisible by 3 with the word "Fizz" and the numbers divisible by 5 with the word "Buzz". Additionally, for numbers divisible by both 3 and 5, replace them with the word "FizzBuzz".
codefeedback
Output an array that contains all the unique elements from two input arrays, but only if they are prime numbers. arr1 = [1, 2, 3, 4, 5, 6], arr2 = [2, 3, 4, 5, 6, 7]
codefeedback
Design a neural network to classify the outcome of a coin toss with a minimum accuracy of 95% on a test set of 1000 coin tosses.
codefeedback
Write a query in SQL to find the name of the employee with the largest salary, excluding any employees whose name starts with the letter 'A'.
codefeedback
Generate HTML to highlight every occurrence of the third word in a given string. For example, if the string is "Hello world! This is a hello world program.", the expected output would be: "Hello world! This is a <span style='background-color: yellow;'>hello</span> world program."
codefeedback
Update the following code to return the key of the highest value in the dictionary. If there are multiple keys with the same highest value, return a list of all those keys in alphabetical order. sample_dict = {"a":1, "b":2, "c": 3, "d":3, "e":2}
codefeedback
Write a CSS code to style the following HTML structure: <div class='container'> <h1>Welcome</h1> <p class='description'>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> </div> Requirements: 1. The container should have a background color of #F2F2F2 and a padding of 20px. 2. The heading should have a f...
codefeedback
Modify the program to read data from the column 'Comments' in the table 'Users' where the data is stored as a JSON string.
codefeedback
Rearrange the array so that each element is divisible by 3. Additionally, ensure that the rearranged array maintains its original relative order of elements. Example: Input: [5, 12, 17, 30, 11] Output: [12, 30, 5, 17, 11] Note: In the output, 12 and 30 are both divisible by 3 and have maintained their original rela...
codefeedback
Write an Assembly language code to calculate the result of multiplying the contents of two memory locations and storing the result in a third memory location. The memory locations must be specified by the user as input.
codefeedback
Generate a valid HTML page with the following styles and content: 1. Set the background color of the page to yellow. 2. Add a padding of 10 pixels to all sides of the page. 3. Create a heading with the text "Hello World!" and center it horizontally on the page. 4. Add a border to the heading with a thickness of 1 pixe...
codefeedback
Create a switch statement to provide different output depending on the given input. Input: "5" Expected Output: "The number is odd" Erroneous Code Reference: switch (input) { case 5: System.out.println("The number is odd"); break; ...
codefeedback
Define a function which can generate a list of 15 unique random numbers between 1 to 30, without using any built-in functions or libraries for generating random numbers.
codefeedback
Create a regex pattern to extract all phone numbers from a given string. Additionally, you need to handle the following scenarios: 1. Some phone numbers may be formatted with parentheses, such as (123) 456-7890. 2. Phone numbers may include an optional country code, such as +1-123-456-7890. 3. There may be multiple pho...
codefeedback
Find a Python solution for this leetcode problem. Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, but you are not allowed to use the same element twice. Provide a piece of erroneous code as a refe...
codefeedback
Using the "for" loop, print out all odd numbers from 1 to 10, excluding the number 5 and ensuring that the code runs within a time complexity of O(n).
codefeedback
Improve the following implementation of a binary search algorithm by using a recursive approach instead of an iterative approach. def binary_search(array, target, low, high): if low <= high: mid = (low+high)//2 if array[mid] == target: return mid elif array[mid] < target: return binary_search...
codefeedback
Write a Java web service that takes in an input string and returns the string "Hello world" if the input is a palindrome. The web service should handle multiple concurrent requests and should be able to handle large input strings efficiently.
codefeedback
Implement a computationally efficient algorithm to solve the following problem: Given an array of integers, check if the sum of any two integers in the array is divisible by 10. The array may contain duplicates, and the algorithm should handle this properly.
codefeedback
Write code to solve this DP(Dynamic Programming) problem from LeetCode. You are given coins of different denominations and a total amount of money. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, retu...
codefeedback
Generate a sum of square numbers from 1 to 10.
codefeedback
Explain in one sentence the concept of inheritance in object-oriented programming and provide an example code snippet.
codefeedback
Write a code to store the user input in a list and then find the average of the items in the list. However, ensure that the code throws an error if the user enters a non-numeric value.
codefeedback
Edit the following code to allow for the user to input an unlimited list of numbers. The program should stop accepting input when the user enters a negative number. After all the numbers have been entered, the program should display the sum and average of the numbers.
codefeedback
Use C# to create a function that takes in a string and count the number of uppercase characters within the string. The function should also return the count of lowercase characters and the count of special characters within the string.
codefeedback
Write a code in PHP to display the top 5 most viewed pages in a website, considering that each page can have multiple views from different users. Additionally, the code should only consider the views from the last 24 hours.
codefeedback
Using the SQL query given below, add a new column called 'total_Quantity' to the table output which is the sum of quantity of all the orders by customer_id. However, there is a mistake in the given query. Find and correct the error. SELECT customer_id, item_id, quantity FROM orders;
codefeedback
Write a Python code snippet to find the index of the second occurrence of a substring in a given string. The substring should be case-sensitive. "Python is an interpreted, high-level, general-purpose programming language." "General-Purpose" Requirements: - The code should have a time complexity of O(n), where n is th...
codefeedback
Create a C++ program to generate a multiplication table of size n x m, where n and m are positive integers greater than or equal to 1. The program should take input for the values of n and m from the user. The program should output the multiplication table as a 2-dimensional array. The values in the array should be ca...
codefeedback
Using the code given below, add JavaScript code to make the hyperlinks open in a new tab, but only if the user is using a mobile device. Otherwise, the hyperlinks should open in the same tab. <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul>
codefeedback
Build a state machine to simulate a vending machine that can handle multiple types of products and accept different forms of payment, such as cash, credit cards, and mobile payments. Additionally, the vending machine should have the ability to provide change and track inventory for each product.
codefeedback
Suggest a better design for the following JavaScript code to match the DRY principle and also ensure that the total_calorie variable is calculated dynamically based on the calorie values of the fruits.
codefeedback
Create a SQL query to return the information about the student's name, grade, city, and the subject they failed in, with the grade below 50. Explanation: 1. The original query only asked for the student's name, grade, and city. We can increase the difficulty by also retrieving the subject they failed in. 2. We want to...
codefeedback
Add the following content to the existing MongoDB database. The content must be encrypted using a symmetric encryption algorithm before being stored in the database. The encryption key should be randomly generated for each document and stored securely in a separate collection. Additionally, the city field should only a...
codefeedback
Create a class in Python that keeps track of the records of animals in the zoo. The class should have a method that allows adding a new animal to the records, but it should only allow adding animals that have a unique identifier. Additionally, the class should have a method to remove an animal from the records based on...
codefeedback
Keep only the characters from the input string that have a numerical value from 0 to 9 and arrange them in ascending order. The resultant number should be a multiple of 3 and have exactly 5 digits. The input string may have a maximum length of 100 characters.
codefeedback
Suggest how to optimize the following MySQL query to find customers whose last name starts with 'Smith' and have made at least 5 purchases in the last 30 days.
codefeedback
Create a dictionary that has the keys and values of a given list, but with a time complexity of O(n^2), where n is the length of the list. my_list = [2, 4, 6, 8]
codefeedback
Write an algorithm that returns the word with the most vowels in the sentence. However, the algorithm should not use any built-in functions or methods for counting vowels or manipulating strings. The algorithm should have a time complexity of O(n), where n is the length of the sentence, and a space complexity of O(1).
codefeedback
Write a Java program to perform a binary search on a sorted array to find a given number. array = [2, 4, 6, 8, 10, 12, 14, 16] to_find = 12
codefeedback
Calculate the result of the expression 5*10-3/2 in PHP.
codefeedback