instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
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). The array will only contain positive integ...
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 You are not allowed to use any loop structures (such as for loops, while loops) or recursion in your solution. You can only use basic arithmetic...
codefeedback
Implement the insertion sort algorithm to sort a list of strings in descending order based on the length of each string. Additionally, the algorithm should handle duplicate strings and sort them in lexicographical order.
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. Please note that the dictio...
codefeedback
Design a data structure to keep track of a student's marks for multiple courses and calculate their overall grade. #Explanation# In addition to keeping track of a student's marks for multiple courses, the data structure should now be able to calculate their overall grade based on different weightage for each course. T...
codefeedback
Write a function that takes two strings and determines if they are an anagram. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should return True if the strings are anagrams and False otherwise. To solve this problem, the function can follow these steps: 1. Conv...
codefeedback
Convert the given string to a list containing the words in the string, excluding any words that start with a vowel. The input string will not contain any punctuation marks and will consist only of lowercase alphabets. The output list should be sorted in descending order based on the length of the words. The time comple...
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
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. The order total should be stored as a decimal with precision of 10 and scale of 2. The order date s...
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. Additionally, implement a program that simulates the movement of virtual occupants within the 3D model,...
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. Additionally, the Swift dictionary should only include keys that start with a vowel letter and the values should ...
codefeedback
Write a CSS program that changes 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. Final...
codefeedback
Write a C program to output all prime numbers from 0 to 1000, using the Sieve of Eratosthenes algorithm. #Erroneous Code# Write a C program to output all prime numbers from 0 to 500, but mistakenly implement the Sieve of Eratosthenes algorithm incorrectly.
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. Implement this functionality using only core graphics and without using any built-in button classes or libraries.
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. Special characters include, but are not limit...
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 allow the user to filter out common stop words, specify the maximum number of words to be displayed, and also sort the words based on their frequency in ascending or descendi...
codefeedback
Create a function in R to determine the probability of rolling a biased dice with a given number of sides, considering that each face has a different probability of being rolled. The probability for each face should be provided as input to the function. The function should also take into account the possibility of rol...
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.). Additionally, optimize the solution to have a time complexity of O(n), where n is the length of the string. string = "This is a testing string and I have tested...
codefeedback
Write an SQL query to list all the customers who have purchased at least one item from each category and have made at least 5 purchases in total.
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
Generate Fibonacci numbers up to 10^8 using a while loop. Additionally, implement error handling to account for integer overflow when calculating large Fibonacci numbers.
codefeedback
Write a HTML code snippet to create a nested ordered list containing 20 economic terms. Each economic term should have a corresponding definition as a list item within the nested list. Additionally, the terms and definitions should be dynamically generated from an array of objects containing the term and definition dat...
codefeedback
Enhance the difficulty of the given programming test question by adding the following additional constraints and requirements to the original problem, adding approximately 10 additional words. Generate a Vue.js component to display a table with the following advanced requirements: 1. The table should have at least 10 ...
codefeedback
Write a Java program to convert a given integer value to its Roman numeral representation, while also ensuring that the input value is within the range of -5000 to 5000.
codefeedback
Create a SQL query to retrieve all employees whose age is equal to or greater than 30 and have a salary greater than $70,000. Write the query in the output field.
codefeedback
Write a SQL query to display the names, addresses, and total number of purchases made by each customer in the last 30 days. Include customers who have not made any purchases in the result set, showing their total number of purchases as 0.
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, account for time zones, and validate the input to ensure it is a valid date. Additionally, the function should return the age in both years and months, rounded down to the nearest whole numb...
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. Additionally, the first name should not exceed 20 characters and...
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(log n),...
codefeedback
Create an SQL query to retrieve all records from a table where the values of two columns do not match, the values of a third column are greater than 100, and the values of a fourth column are unique. Additionally, the query should order the results in descending order based on the values of the fourth column.
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, different casing, and multiple whitespace characters. Additionally, the function should ignore common stopw...
codefeedback
Create a three-dimensional array of length 3×2×2 with all elements set to 0. 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 set to its inde...
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
Generate a valid C++ code to print the next 100 prime numbers, but also ensure that the code handles input validation for the number of prime numbers to be printed.
codefeedback
Generate a Python program to perform matrix multiplication using only bitwise operations, without using any built-in functions or libraries, and the matrix dimensions must be a power of 2.
codefeedback
Write a HTML page that displays a welcome message and prompts the user to enter their name in a form. Implement client-side validation to ensure that the user's name meets the following requirements: - The name must contain at least one uppercase letter, one lowercase letter, and one special character. - The name must ...
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. Instead of using built-in json parsing functions, you should im...
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 100 elements and each element should be within the range of -1000 to 1000, inclusive. The program should also print the number of comparisons and swaps made during the sorting proces...
codefeedback
Write a pseudocode for a function that takes a list of integers as input and prints the numbers in ascending order. The function should also remove any duplicate numbers from the list before printing. Additionally, the function should ensure that the time complexity of the sorting algorithm used is O(nlogn), where n is...
codefeedback
Create a JavaScript program to print out a pattern of numbers in a specific format. ## Examples: 1. For input `5`, the program should print: ``` 1 23 456 78910 1112131415 ``` 2. For input `3`, the program should print: ``` 1 23 456 ``` 3. For input `6`, the program should print: ``` 1 23 456 78910 1112131415 1617181...
codefeedback
Complete the following Python program for converting the given list into a dictionary, while ensuring that all keys are unique and have a length of at least 3 characters. list1 = ['apple', 'ball', 'cat'] list2 = [1, 2, 3] def to_dict(list1, list2): ??? Requirements: 1. The function should take two lists as input...
codefeedback
Edit this C++ code to remove all comments and print the total number of comments removed at the end of the program. int main() { /* This is a multiline comment */ std::cout << "Hello World"; int commentCount = 0; // variable to keep track of comment count // loop to remove comments wh...
codefeedback
Modify the given code to be able to print a diamond pattern as specified in the output. The program should also validate the input to ensure that the number of rows is a positive odd integer. Additionally, the program should prompt the user to enter the number of rows instead of using a fixed value. The output should h...
codefeedback
Suggest a command-line program or script that can find out the IP address of a domain using a recursive DNS resolver, ensuring that the command outputs the IPv4 address only. The program should handle multiple domain names as input and display the IP addresses in ascending order. Additionally, the program should implem...
codefeedback
Write a Python program to find the compound interest, considering the possibility of multiple interest rates and varying compounding periods. Given the initial principal amount of 1000, find the compound interest after 5 years, where the interest rates are 3%, 4%, and 5% respectively for the first, second, and third ye...
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. Additionally, the program should display the file size and last modified date of each file, and exclude any hidde...
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". However, instead of using the modu...
codefeedback
Write a code to print a count-down timer with the following constraints: 1. The timer should start from a user-defined number and count down by 1 every millisecond. 2. The program should only allow positive integer inputs for the starting number. 3. The timer should stop when it reaches zero and display a message indi...
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' and whose salary is greater than $100,000.
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
Generate a 2D list of size 5x5 with random numbers between 0 and 9. Each row and column must contain at least one unique number. Additionally, the sum of all numbers in the diagonal from the top left to bottom right corner of the 2D list should be greater than the sum of all numbers in the diagonal from the top right t...
codefeedback
Design a neural network to classify the outcome of a coin toss with a minimum accuracy of 98% on a test set of 10000 coin tosses. The neural network should also be able to classify the outcome in real-time, with a maximum latency of 10 milliseconds per prediction. Additionally, the neural network should be able to hand...
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. Additionally, the function should only iterate through the dictionary once. sample_dict = {"a":1, "b":2, "c": 3, "d":3, "e":...
codefeedback
Output an array that contains all the unique elements from two input arrays, but only if they are prime numbers. The prime numbers must be sorted in ascending order. arr1 = [10, 15, 18, 20, 23, 25, 30], arr2 = [12, 14, 15, 16, 19, 20, 21, 22, 23, 25] Time Complexity: O(n log n) Space Complexity: O(n) Example: Input:...
codefeedback
Implement a lexical analyzer in Python that tokenizes a given input string into a sequence of tokens. The tokens should include identifiers, keywords, operators, literals, and punctuation symbols. Your lexical analyzer should be able to handle multiple programming languages, such as Python, Java, and C++. Provide a det...
codefeedback
Write a code to print a human-readable description of a given HTTP status code, while also converting the status code to its corresponding status message. Example Input: HTTP Status Code: 503 Example Output: Status Code: 503 Status Message: Service Unavailable Additional Requirements: 1. Your code should handle inva...
codefeedback
Design an algorithm that searches for a target element in a sorted array with a time complexity of O(log n) and without using any built-in search functions or libraries, where n is the number of elements in the array. arr = [1, 3, 5, 6, 7] target = 6
codefeedback
Modify the program to read data from the column 'Comments' in the table 'Users' where the data is stored as a JSON string. The program should then parse the JSON string and extract the values for the keys 'name' and 'email' for each comment. Finally, print the extracted values for all the comments in the table.
codefeedback
Given an array of integers, return an array where each element is repeated twice, and the order of the repeated elements should be reversed compared to the original array. The array should also be sorted in ascending order. arr = [1, 2, 3, 4] Additional Constraints: - The length of the array should be at least 2. - Th...
codefeedback
Write a function that takes a list of integers and multiplies each integer by its index in the list. The function should return a new list with the multiplied values. The function should have a time complexity of O(n), where n is the length of the input list. Additionally, the function should handle negative integers i...
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, 15, 8, 9, 22, 18] Output: [12, 30, 15, 9, 18, 5, 17, 11, 8, 22] Note: In the output, 12, 30, 15, 9, 18 are all divisible b...
codefeedback
Using the "for" loop, print out all prime numbers from 1 to 100, excluding the number 2 and ensuring that the code runs within a time complexity of O(n^2).
codefeedback
Find a Python solution for this leetcode problem with additional constraints. Given an array of integers, return indices of the two numbers such that they add up to a specific target. The array will contain at least two elements and at most 10^5 elements. Each element in the array will be an integer in the range of -10...
codefeedback
Define a function which can generate a list of 1000 unique random numbers between 1 to 10000, without using any built-in functions or libraries for generating random numbers. #Reasoning# To generate a list of 1000 unique random numbers between 1 and 10000 without using any built-in functions or libraries for generatin...
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
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. Additionally, you must ensure that the multiplication operation is performed using only bitwise oper...
codefeedback
Create a multi-step registration process for a website. The registration process should consist of three steps: Step 1: Collect User Information - Create an HTML form that can process the user's email address, password, full name, and date of birth. Implement client-side validation to ensure that the email address is ...
codefeedback
What data structure should be used to store a set of strings, with the requirement that the time complexity for insertion, deletion, and search operations should be O(1)? Additionally, the maximum size of the set should be limited to 100 strings, and the data structure should support a method to retrieve the least rece...
codefeedback
Increase the difficulty of the binary search algorithm by adding a requirement to handle duplicate elements in the array. Improve the following implementation of a binary search algorithm by using a recursive approach instead of an iterative approach and handling duplicate elements in the array. def binary_search(arr...
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. In addition to the given requirements, the web service should also validate ...
codefeedback
Create a Python function that takes a list of integers as input and returns a list containing only the prime numbers in the input list. The function should have a time complexity of O(n^2), where n is the length of the input list.
codefeedback
Create a SQL query to find all users from the “users” table who have a last name of “Smith” and have registered on the website within the last 7 days. Additionally, retrieve the number of posts made by each of these users in the last 7 days.
codefeedback
Generate a sum of square numbers from 1 to N, where N is a positive integer greater than 10. The solution should have a time complexity of O(N) and a space complexity of O(1).
codefeedback
Please write a dynamic programming algorithm to solve the following problem from LeetCode. You are given an array of integers representing different denominations of coins and a target amount of money. Write a function to compute the fewest number of coins needed to make up that amount. You can use any combination of ...
codefeedback
Create an array with values two and six repeated twenty times, but ensure that the array contains exactly 40 elements and each value occurs at least twice.
codefeedback
Edit the following code to allow for the user to input an unlimited list of positive numbers. The program should stop accepting input when the user enters a negative number or a non-numeric input. Additionally, the program should display the minimum and maximum numbers entered by the user. After all the numbers have be...
codefeedback
Write a code to store the user input in a list and then find the average of the positive integers in the list. However, ensure that the code throws an error if the user enters a non-numeric value or a negative number.
codefeedback
Write a code in JavaScript to make all letters in a string upper case, but exclude any digits or special characters. Additionally, capitalize the first letter of each word in the string. <input_str="hello world! 123" >
codefeedback
Convert the list of numbers into a dictionary where the numeric values are the keys and the corresponding characters are the values. However, only include the numbers that are prime numbers as keys in the dictionary. Additionally, if a prime number appears multiple times in the num_list, use the corresponding characte...
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" Additional Requirements: - The code should handle strings containing non-alph...
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. The code should be able to handle a large dataset of millions of views efficiently, without usin...
codefeedback
## Problem Create a function to swap two elements of an array in JavaScript. The function should have a time complexity of O(1) and should not use any built-in array methods or additional data structures. Implement function `swapElements(arr: number[], index1: number, index2: number): number[]`, where: - `arr` is an ...
codefeedback
Use C# to create a function that takes in a string and counts 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. Additionally, the function should determine the frequency of each character in the ...
codefeedback
Write a JavaScript function called "deleteFirstOccurrence" that takes two parameters: an array and an item. The function should delete the first occurrence of the item from the array and return the modified array. If the item is not found in the array, the function should return the original array unchanged. To solve ...
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
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. Additionally, sort the results in descending order based on the grade. Explanation: 1. The original query only asked for the student's name, grade, and city. We can increase the ...
codefeedback
Propose an efficient algorithm to remove duplicates from a given list while preserving the order of the remaining elements. Input: A list of integers, `my_list`, where the length of the list is `n` and the elements in the list are integers between -10^9 and 10^9. Output: A list containing the unique elements from `my...
codefeedback
Using the code snippet given below, add a unique class called btn which will remove the default styles from the submit button. Additionally, implement a function that will dynamically change the submit button's text to "Submit" in uppercase letters when the button is clicked. Finally, validate the email input field to ...
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. In order to increase th...
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. Additionally, if the user is on a desktop device, the code should check if the user has a specific browser version installed and...
codefeedback
Calculate the total area of a circle given the diameter and the number of sides of an inscribed regular polygon within the circle. The sides of the polygon are tangent to the circle. The number of sides can be any positive integer greater than or equal to 3. Inputs: - diameter: a positive integer representing the diam...
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
Suggest how to optimize the following MySQL query to find customers whose last name starts with 'Smith', have made at least 5 purchases in the last 30 days, and have an average purchase amount greater than $100.
codefeedback
Given a string of alphanumeric characters, write a function to find the longest substring that contains only numeric characters and has a sum of digits that is a multiple of 5. The function should return the length of the longest substring. The input string may have a maximum length of 1000 characters. The function s...
codefeedback
Describe how to handle a POST request in Express while also implementing data validation for the request body. Additionally, you need to implement error handling and return appropriate error messages for different validation failures.
codefeedback
How many hypernyms are there in WordNet for the given word "cat" that have a depth level greater than or equal to 2?
codefeedback
Split a given string according to the given delimiter. However, the delimiter can be more than one character long and can also be a regular expression. Example: Input: my_string = "This is a test string" delimiter = "is" Output: ["Th", " ", " a test string"] Input: my_string = "This is a test string" delimiter = "[...
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
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. The dictionary should only include the elements from the list that are divisible by 2. Additionally, the dictionary should not include any duplicate keys, and the values should be s...
codefeedback
Create a Boolean expression in Python to check if a number is a multiple of both 5 and 7, is greater than 100, and has exactly three distinct prime factors.
codefeedback